Skip to content

ARROW-16692: [C++] StackOverflow in merge generator causes segmentation fault in scan - #13691

Merged
westonpace merged 2 commits into
apache:masterfrom
westonpace:bugfix/ARROW-16692--merge-gen-stack-overflow
Jul 25, 2022
Merged

westonpace merged 2 commits into
apache:masterfrom
westonpace:bugfix/ARROW-16692--merge-gen-stack-overflow

Conversation

@westonpace

Copy link
Copy Markdown
Member

Fix for the merged generator to avoid a potential stack overflow

@github-actions

Copy link
Copy Markdown

@westonpace

Copy link
Copy Markdown
Member Author

There is some high level description of the problem & the fix in https://issues.apache.org/jira/browse/ARROW-16692

@westonpace
westonpace requested a review from lidavidm July 23, 2022 00:07

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The longer term plan is to replace all this with the push-based plan, right? Or does this have to stay for dataset?

@westonpace

Copy link
Copy Markdown
Member Author

The longer term plan is to replace all this with the push-based plan, right? Or does this have to stay for dataset?

Yes, as part of ARROW-16072.

@westonpace

Copy link
Copy Markdown
Member Author

Hmm, sadly https://github.com/apache/arrow/runs/7477126709?check_suite_focus=true seems relevant. Perhaps this is leading the merge generator to not properly discard its state.

@westonpace

Copy link
Copy Markdown
Member Author

I investigated the failing ASAN run further today. I'm able to reproduce it on master so it is unrelated to this change. The root problem is the same one that motivates ARROW-16072. From the JIRA:

We've hit a bit of a wall with the merged generator. The current behavior is: If one subscription encounters an error we simply stop pulling from the other subscriptions. Once everything has settled down we return the error and end the stream.

In reality, we should be sending some kind of cancel signal down to the other generators. Otherwise, we are not respecting the rule for AsyncGenerator that we recently defined which is "An AsyncGenerator should always be fully consumed".

The end result of this is that some bits of the scanner keep running in the event of a failure or an abort. These pieces keep their state alive via shared_ptr so it doesn't actually cause any exceptions. However, it can lead to cases like this memory leak.

The last test in ScannerTest will test a failed scan. This causes some bits to be left running. Then the test ends and the process shuts down and the thread pool shuts down immediately. This causes some cleanup thread tasks to fail to get scheduled or not run. As a result there is some leakage at shutdown.

This is only a shutdown leak and so pretty minor. ARROW-16072 will tie cancellation into the scanner so that once a plan is aborted and the user waits for it to finish then nothing will be left running and there will be no possibility for this.

Long story short, I think we can proceed with merging this PR.

@westonpace

Copy link
Copy Markdown
Member Author

I've filed ARROW-17198 for the memory leak.

@lidavidm

Copy link
Copy Markdown
Member

Can we add an ASAN suppression temporarily before merging?

@lidavidm

Copy link
Copy Markdown
Member

(Also probably worth doing the same for Valgrind)

@westonpace
westonpace force-pushed the bugfix/ARROW-16692--merge-gen-stack-overflow branch from 5176792 to bdf66fb Compare July 25, 2022 17:24
@westonpace

Copy link
Copy Markdown
Member Author

Can we add an ASAN suppression temporarily before merging?

I added a WaitForIdle at the end of the test. This should prevent any possible leak, from this test at least.

@westonpace

Copy link
Copy Markdown
Member Author

Failure seems unrelated. I'm going to merge.

@westonpace
westonpace merged commit 898e12e into apache:master Jul 25, 2022
@ursabot

ursabot commented Jul 26, 2022

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = 4e37149 and contender = 898e12e. 898e12e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Failed ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.41% ⬆️0.0%] test-mac-arm
[Finished ⬇️0.0% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️1.07% ⬆️0.0%] ursa-thinkcentre-m75q
Buildkite builds:
[Failed] 898e12e6 ec2-t3-xlarge-us-east-2
[Finished] 898e12e6 test-mac-arm
[Finished] 898e12e6 ursa-i9-9960x
[Finished] 898e12e6 ursa-thinkcentre-m75q
[Failed] 4e371496 ec2-t3-xlarge-us-east-2
[Finished] 4e371496 test-mac-arm
[Finished] 4e371496 ursa-i9-9960x
[Finished] 4e371496 ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

kszucs pushed a commit that referenced this pull request Jul 26, 2022
…on fault in scan (#13691)

Fix for the merged generator to avoid a potential stack overflow

Authored-by: Weston Pace <[email protected]>
Signed-off-by: Weston Pace <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants