cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Overwrite Job Errors

inaafina
New Contributor

I keep on getting this error message when trying to create a parquet in my notebook. Has anyone found this error too? My overwrite path was working perfectly fine before.

SparkConnectGrpcException: (java.lang.IllegalStateException) operationId: d5871ddd-4b1c-4838-a074-9a42a66e28ee with status ReadyForExecution is not within statuses List(Finished, Failed, Canceled) for event Closed

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

yasmeen
Contributor

 Hi @inaafina ,

The error comes from Spark Connect, the client-server layer Databricks uses on serverless compute and standard (formerly shared) access mode clusters. It usually means the Spark session that ran your command had expired or been closed before the operation finished. The serverโ€™s cleanup then found the operation stuck in ReadyForExecution and raised this error.

So itโ€™s normally a session or compute problem, not a problem with your Parquet code. That fits with your overwrite path working before.

Possible solutions, quickest first

1. Start a fresh session. This fixes most cases.

  • In the notebook, detach and reattach compute, or use Run > Restart Python / Reset session.
  • On serverless, reconnect or reset the environment.
  • Rerun the setup cells (imports, variables, DataFrame definitions), then the write.

2. Check whether the compute restarted or timed out. If the cluster auto-terminated, restarted, or the notebook sat idle for a long time, the old session is gone. Rerun from the top instead of only the last cell.

3. Retry the write. The error can be transient. For scheduled jobs, add a simple retry:

 
python
import time

for attempt in range(3):
    try:
        df.write.mode("overwrite").parquet(target_path)
        break
    except Exception as e:
        if attempt == 2:
            raise
        print(f"Write failed, retrying: {e}")
        time.sleep(30)

4. Check that you arenโ€™t reading and overwriting the same path. If df was built by reading from target_path, overwriting that path in the same query deletes the files Spark is still reading. That fails, and on Spark Connect it can surface as a confusing error like this one. Write to a temporary path first, or materialize the data before overwriting.

5. Use a supported location. On serverless and standard access mode, write to a Unity Catalog volume or an external location rather than DBFS root or mount paths:

 
python
df.write.mode("overwrite").parquet("/Volumes/<catalog>/<schema>/<volume>/my_output")

6. Consider Delta instead of plain Parquet. A Delta overwrite is atomic: readers never see a half-written folder, and a failed write doesnโ€™t leave partial files.

 
python
df.write.format("delta").mode("overwrite").saveAsTable("<catalog>.<schema>.my_table")

7. Try a newer runtime or different compute. Because itโ€™s a Spark Connect bug, a newer Databricks Runtime or serverless environment version may fix it. As a workaround, run the notebook on a dedicated (single user) access mode cluster, which doesnโ€™t route Python through Spark Connect the same way.

8. If it keeps happening: capture the full stack trace and the operationId from the error, check the driver logs, and raise a Databricks support ticket. The operation ID lets support trace the exact session.

To narrow it down: are you on serverless or a cluster, and which path are you writing to (DBFS, a volume or cloud storage)? Also, is the DataFrame read from the same path youโ€™re overwriting?

View solution in original post

Louis_Frolio
Databricks Employee
Databricks Employee

Hello @inaafina, I took a look at both internal and external documentation and here is what I found.

This is a Spark Connect lifecycle error, and your Parquet code is probably fine. Spark Connect is the client-server layer notebooks use on serverless and standard access mode compute. The server tried to close an operation it still had marked as ReadyForExecution, which usually means the session expired or was released underneath it. @yasmeen explained that part well.

The signature matches a known Apache Spark bug, SPARK-50176. In that report the overwrite finished and the data was correct, but the client never got its response and the server threw this error during cleanup. It showed up on large, long-running writes, affected Spark 3.5.2, and was fixed in 3.5.4.

Here's what I'd do, in order:

  1. Check the target path before you rerun. The write may have completed.
  2. Start a fresh session (detach and reattach, or reset on serverless) and rerun from the top, as @yasmeen suggested.
  3. Check your runtime. DBR 16.4 LTS is built on Spark 3.5.2, so if you're there, try a newer runtime. I can't confirm from public sources whether the fix was backported to 16.4 maintenance updates.
  4. If you're running from a local IDE instead of a workspace notebook, match databricks-connect to your runtime version. @Satyasai is right that the client version matters, and @saurabh18cs's databricks environments setup-local command is the easy way to build a matching environment.
  5. If it still reproduces, open a support ticket with the operationId and driver logs.

Two cautions, though. spark.connect.client.session.timeout isn't in the documented Spark configuration, so it may be silently ignored. And @Satyasai's repartition tip won't fix the root cause, though it can shorten a very long write. Longer term, @yasmeen's suggestion to use Delta instead of plain Parquet makes overwrites much safer, since the commit is atomic.

References:

If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.

Regards, Louis.

View solution in original post

5 REPLIES 5

Satyasai
Contributor

@inaafina 

1. Upgrade Databricks Connect and gRPC Packages
If you are using an external IDE to run this workflow using Databricks Connect then you may experience gRPC state race conditions if your client is out of date. Upgrade your local Python packages to the latest versions.

Bash
pip install --upgrade databricks-connect grpcio grpcio-status
Databricks have made several improvements in their clients to improve stability around proxies dropping and sessions throwing exceptions.

2. Optimize or Repartition Large Overwrites
If you are overwriting a large dataset then you may be reaching the timeout or payload limits on the gRPC channel due to the high volume of data being serialised.

You can re-partition your data before overwriting. This will reduce any skew in your partitions or split large datasets into smaller ones.

Python
df.repartition(200).write.mode("overwrite").parquet("path/to/data")

3. Increase Timeout for Spark Connect Client
If you are taking a long time to stage your writes then you may get a timeout on the gRPC channel. You can increase these timeout values using your Spark session configurations.

Python
spark.conf.set("spark.connect.client.session.timeout", "600s")

saurabh18cs
Honored Contributor III

Hi  @inaafina setup like this , this is a new way to automatically resolve right package versions based on your compute. you have to use databricks cli

saurabh18cs_0-1794843336022.png

 

 

e.g. databricks environments setup-local \ --serverless-version 5 \ --dry-run

yasmeen
Contributor

 Hi @inaafina ,

The error comes from Spark Connect, the client-server layer Databricks uses on serverless compute and standard (formerly shared) access mode clusters. It usually means the Spark session that ran your command had expired or been closed before the operation finished. The serverโ€™s cleanup then found the operation stuck in ReadyForExecution and raised this error.

So itโ€™s normally a session or compute problem, not a problem with your Parquet code. That fits with your overwrite path working before.

Possible solutions, quickest first

1. Start a fresh session. This fixes most cases.

  • In the notebook, detach and reattach compute, or use Run > Restart Python / Reset session.
  • On serverless, reconnect or reset the environment.
  • Rerun the setup cells (imports, variables, DataFrame definitions), then the write.

2. Check whether the compute restarted or timed out. If the cluster auto-terminated, restarted, or the notebook sat idle for a long time, the old session is gone. Rerun from the top instead of only the last cell.

3. Retry the write. The error can be transient. For scheduled jobs, add a simple retry:

 
python
import time

for attempt in range(3):
    try:
        df.write.mode("overwrite").parquet(target_path)
        break
    except Exception as e:
        if attempt == 2:
            raise
        print(f"Write failed, retrying: {e}")
        time.sleep(30)

4. Check that you arenโ€™t reading and overwriting the same path. If df was built by reading from target_path, overwriting that path in the same query deletes the files Spark is still reading. That fails, and on Spark Connect it can surface as a confusing error like this one. Write to a temporary path first, or materialize the data before overwriting.

5. Use a supported location. On serverless and standard access mode, write to a Unity Catalog volume or an external location rather than DBFS root or mount paths:

 
python
df.write.mode("overwrite").parquet("/Volumes/<catalog>/<schema>/<volume>/my_output")

6. Consider Delta instead of plain Parquet. A Delta overwrite is atomic: readers never see a half-written folder, and a failed write doesnโ€™t leave partial files.

 
python
df.write.format("delta").mode("overwrite").saveAsTable("<catalog>.<schema>.my_table")

7. Try a newer runtime or different compute. Because itโ€™s a Spark Connect bug, a newer Databricks Runtime or serverless environment version may fix it. As a workaround, run the notebook on a dedicated (single user) access mode cluster, which doesnโ€™t route Python through Spark Connect the same way.

8. If it keeps happening: capture the full stack trace and the operationId from the error, check the driver logs, and raise a Databricks support ticket. The operation ID lets support trace the exact session.

To narrow it down: are you on serverless or a cluster, and which path are you writing to (DBFS, a volume or cloud storage)? Also, is the DataFrame read from the same path youโ€™re overwriting?

Louis_Frolio
Databricks Employee
Databricks Employee

Hello @inaafina, I took a look at both internal and external documentation and here is what I found.

This is a Spark Connect lifecycle error, and your Parquet code is probably fine. Spark Connect is the client-server layer notebooks use on serverless and standard access mode compute. The server tried to close an operation it still had marked as ReadyForExecution, which usually means the session expired or was released underneath it. @yasmeen explained that part well.

The signature matches a known Apache Spark bug, SPARK-50176. In that report the overwrite finished and the data was correct, but the client never got its response and the server threw this error during cleanup. It showed up on large, long-running writes, affected Spark 3.5.2, and was fixed in 3.5.4.

Here's what I'd do, in order:

  1. Check the target path before you rerun. The write may have completed.
  2. Start a fresh session (detach and reattach, or reset on serverless) and rerun from the top, as @yasmeen suggested.
  3. Check your runtime. DBR 16.4 LTS is built on Spark 3.5.2, so if you're there, try a newer runtime. I can't confirm from public sources whether the fix was backported to 16.4 maintenance updates.
  4. If you're running from a local IDE instead of a workspace notebook, match databricks-connect to your runtime version. @Satyasai is right that the client version matters, and @saurabh18cs's databricks environments setup-local command is the easy way to build a matching environment.
  5. If it still reproduces, open a support ticket with the operationId and driver logs.

Two cautions, though. spark.connect.client.session.timeout isn't in the documented Spark configuration, so it may be silently ignored. And @Satyasai's repartition tip won't fix the root cause, though it can shorten a very long write. Longer term, @yasmeen's suggestion to use Delta instead of plain Parquet makes overwrites much safer, since the commit is atomic.

References:

If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.

Regards, Louis.

Isaac_18
Contributor II

Hi @inaafina, adding a bit more context on this one, because the error message is confusing.

That message doesn't come from your parquet write itself. It comes from Spark Connect's bookkeeping for each operation. (Serverless notebooks and Databricks Connect both run on Spark Connect.) Every command gets an operation id and moves through states like Started, ReadyForExecution and Finished. Your operation was told to close while it was still at ReadyForExecution, and the server refused that state change. Open-source Spark has had bugs exactly like this (SPARK-46186 and SPARK-50176, both fixed upstream), usually set off by an interrupt, a dropped connection or a session release arriving at the wrong moment. So "it worked before and nothing in my code changed" fits this well.

What I'd try, in order:

  1. Check whether the write actually landed. In the upstream bug, the data was written fine and only the response got stuck. List the folder or read it back before rerunning:
    display(dbutils.fs.ls("<your output path>"))
    spark.read.parquet("<your output path>").count()
  2. Start a fresh session. In a notebook, detach and reattach (or restart the Python process), then run it again. This error is often tied to one bad session.
  3. If you run it from an IDE with Databricks Connect, make sure the client version matches your compute. That's what @saurabh18cs's databricks environments setup-local suggestion handles. A client that's out of step with the server is a common source of strange gRPC errors.
  4. If it keeps happening on the same cell, consider writing to a Delta table (or a UC Volume path) instead of a raw parquet folder. An overwrite there is a single transaction, and you can check DESCRIBE HISTORY to see whether it committed.

One small note on the earlier reply: I couldn't find spark.connect.client.session.timeout in the Databricks or Spark docs, so I wouldn't count on that setting.

If it still happens after a fresh session, could you share whether this is serverless or classic compute, what kind of path you're writing to (Volume, DBFS, cloud storage), and roughly how big the data is? If it happens every time on serverless, it's worth a support ticket with the operationId from the error, since they can trace it on the server side.