Skip to content

Conversation

liuzqt
Copy link
Contributor

@liuzqt liuzqt commented Aug 29, 2025

What changes were proposed in this pull request?

There is race condition between CachedRDDBuilder.cachedColumnBuffers and CachedRDDBuilder.clearCache: when they interleave each other, cachedColumnBuffers might return a nullptr.

This looks like a day-1 bug introduced from 20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

Why are the changes needed?

The race condition might lead to NPE from here which is basically a null RDD returned from CachedRDDBuilder.cachedColumnBuffers

Does this PR introduce any user-facing change?

NO

How was this patch tested?

Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

Was this patch authored or co-authored using generative AI tooling?

NO

@github-actions github-actions bot added the SQL label Aug 29, 2025
@liuzqt
Copy link
Contributor Author

liuzqt commented Aug 29, 2025

@cloud-fan

@cloud-fan
Copy link
Contributor

cc @yaooqinn

@yaooqinn
Copy link
Member

Can we add the error in pr desc?

@liuzqt
Copy link
Contributor Author

liuzqt commented Aug 31, 2025

Can we add the error in pr desc?

I no longer have the full stacktrace. I put the code path in the PR desc where the NPE was throw.

@cloud-fan
Copy link
Contributor

thanks, merging to master/4.0!

@cloud-fan cloud-fan closed this in 871fe3d Sep 1, 2025
cloud-fan pushed a commit that referenced this pull request Sep 1, 2025
### What changes were proposed in this pull request?

There is race condition between `CachedRDDBuilder.cachedColumnBuffers` and `CachedRDDBuilder.clearCache`: when they interleave each other, `cachedColumnBuffers` might return a `nullptr`.

This looks like a day-1 bug introduced from  20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

### Why are the changes needed?

The race condition might lead to NPE from [here](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/QueryStageExec.scala#L303) which is basically a null `RDD` returned from `CachedRDDBuilder.cachedColumnBuffers`

### Does this PR introduce _any_ user-facing change?
NO

### How was this patch tested?
Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes #52174 from liuzqt/SPARK-53435.

Authored-by: ziqi liu <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 871fe3d)
Signed-off-by: Wenchen Fan <[email protected]>
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @liuzqt and all.

Could you make a backporting PR to branch-3.5, @liuzqt ?

liuzqt added a commit to liuzqt/spark that referenced this pull request Sep 2, 2025
### What changes were proposed in this pull request?

There is race condition between `CachedRDDBuilder.cachedColumnBuffers` and `CachedRDDBuilder.clearCache`: when they interleave each other, `cachedColumnBuffers` might return a `nullptr`.

This looks like a day-1 bug introduced from  apache@20ca208#diff-4068fce361a50e3d32af2ba2d4231905f500e7b2da9f46d5ddd99b758c30fd43

### Why are the changes needed?

The race condition might lead to NPE from [here](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/QueryStageExec.scala#L303) which is basically a null `RDD` returned from `CachedRDDBuilder.cachedColumnBuffers`

### Does this PR introduce _any_ user-facing change?
NO

### How was this patch tested?
Theoretically this race condition might be triggered as long as cache materialization and unpersistence happen on different thread. But there is no reliable way to construct unit test.

### Was this patch authored or co-authored using generative AI tooling?
NO

Closes apache#52174 from liuzqt/SPARK-53435.

Authored-by: ziqi liu <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants