Skip to content

feat(bigquery): heap-box futures and builder in JobPoller to prevent stack overflow - #6237

Draft
haphungw wants to merge 2 commits into
googleapis:mainfrom
haphungw:fix-job-poller-stack-overflow
Draft

feat(bigquery): heap-box futures and builder in JobPoller to prevent stack overflow#6237
haphungw wants to merge 2 commits into
googleapis:mainfrom
haphungw:fix-job-poller-stack-overflow

Conversation

@haphungw

Copy link
Copy Markdown
Contributor

Heap-box JobPoller::until_done future, JobPoller builder, and DiscoveryPoller::until_done.

Job structs are large (~7.1 KB) and cause deep unboxed async future state machines to overflow the default 2 MB thread stack during integration tests.

@product-auto-label product-auto-label Bot added the api: bigquery Issues related to the BigQuery API. label Jul 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates JobPoller in BigQuery and LRO discovery to box the InsertJob builder and return pinned boxed futures from until_done. A critical issue was identified in operation.rs where assigning to *builder after moving builder will cause a compilation error; it is recommended to reassign a new Box to builder instead.

&& attempts < self.policy.job_level_attempt_limit
{
let retry_job = prepare_job_for_retry(job_result);
*builder = builder.set_job(retry_job);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

This assignment will likely cause a compilation error because calling builder.set_job(...) moves the InsertJob out of the Box (moving builder), making it impossible to assign back to *builder. Instead, you should reassign a new Box to builder.

Suggested change
*builder = builder.set_job(retry_job);
builder = Box::new(builder.set_job(retry_job));

&& attempts < self.policy.job_level_attempt_limit
pub fn until_done(
self,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<Job, JobPollerError>> + Send>>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does the signature has to change that much ? isn't this gonna diverge from other LROs that are async and return just a Result ?

Maybe I don't understand Pin/Box enough to understand what is going on here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was struggling to get this test pass due to stack overflow
https://github.com/googleapis/google-cloud-rust/pull/6232/changes#diff-824e62dc84d6a981c4c62f1f254e61712feacc64d410a3a1b0744f981cb657edR267
https://pantheon.corp.google.com/cloud-build/builds;region=us-central1/6916363e-91b1-4147-81c4-2bf87a03abd7?project=rust-sdk-testing&e=SqlStudioMysqlLaunch::SqlStudioMysqlEnabled

The builder and polling loop state machine get pretty huge on the stack, so boxing it offloads that to the heap.
The the .until_done().await caller syntax is still the same, but it seems like I haven't been able to fix the issue.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.04%. Comparing base (5a362fc) to head (16de120).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6237      +/-   ##
==========================================
- Coverage   96.05%   96.04%   -0.01%     
==========================================
  Files         269      269              
  Lines       68390    68390              
==========================================
- Hits        65689    65685       -4     
- Misses       2701     2705       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the BigQuery API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants