Repository navigation
spark bigquery: drain listener bus before stopping Spark - #342
Merged
Merged
Conversation
tnazarew
marked this pull request as ready for review
October 21, 2026 17:23
The script exited right after the write, so the SparkContext could stop while the OpenLineage listener was still handling the write's SQLExecutionEnd. The BigQuery connector's lineage extension then fails with "Cannot call methods on a stopped SparkContext" and the COMPLETE event is emitted with empty outputs (issues #339, #341; Spark 3.5.1, OpenLineage 1.54.0, intermittent). Wait for the listener bus to drain, then stop Spark explicitly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: tnazarew <tomasz.nazarewicz@getindata.com>
tnazarew
force-pushed
the
spark/bigquery-drain-listener-bus
branch
from
October 21, 2026 17:23
9ef37ea to
4d7a3b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the intermittent
bigqueryfailures reported in #339 and #341 (Spark 3.5.1, OpenLineage 1.54.0):(also
dataSource_test_1.38.0,schema_test_1.38.0,columnLineage_test_1.38.0)Cause
test.pyends right after the BigQuery write. Python exits and the SparkContext stops while the OpenLineage listener is still handling the write'sSQLExecutionEnd. When GCS is slow, as in the failing runs, the listener falls behind. The BigQuery connector's lineage extension then throws, and the COMPLETE event is emitted withoutputs: []. From the driver log of Dataproc job6fe0adfc-0bf0-4ca1-ae01-4f1e77e8beb1(run 39567597991):The emitted events: START has 1 input and 1 output, but the COMPLETE event for
writing_to_big_query.execute_save_into_data_source_command.e2e_dataset_wordcount_output_351_1540has 1 input and 0 outputs. It passed on 2026-10-20 and failed on 2026-10-17 and 2026-10-21.Change
After the write, the script waits up to 60 s for Spark's listener bus to drain (
listenerBus().waitUntilEmpty(60000)through py4j), then callsspark.stop(). The OpenLineage listener now finishes while the context is still alive.waitUntilEmpty(long)andSparkContext.listenerBus()are public in the bytecode on Spark 3.1.3 and 3.3.2 (checked withjavap). Tested at runtime on Spark 3.5.1.Notes
bigquery_to_delta,bigquery_to_iceberg,cloudsql,spannerandhivealso end without stopping Spark. They are left unchanged because none of them shows this failure.🤖 Generated with Claude Code