Skip to content

Fix potential stack overflow in _wait_until_complete#301

Open
laz- wants to merge 2 commits into
ryanking13:masterfrom
laz-:fix/wait-until-complete-recursion
Open

Fix potential stack overflow in _wait_until_complete#301
laz- wants to merge 2 commits into
ryanking13:masterfrom
laz-:fix/wait-until-complete-recursion

Conversation

@laz-

@laz- laz- commented Jun 2, 2026

Copy link
Copy Markdown

Summary

_wait_until_complete currently calls itself recursively while waiting for the NetFunnel queue. Under sustained high-traffic conditions the queue wait can be long enough for the recursion depth to grow unboundedly, risking a RecursionError.

This PR converts the implementation to an equivalent iterative while loop, which has identical behaviour with no stack risk.

Changes

  • SRT/netfunnel.py: replace recursive _wait_until_complete with a while True loop; key is updated in-place each iteration instead of being passed as a new recursive argument.

Test plan

  • Existing behaviour is unchanged — the loop still polls chkEnter, sleeps 1 s while nwait != 0, and returns the key once the queue clears
  • No new dependencies or interface changes

🤖 Generated with Claude Code

Converts the recursive implementation to an iterative while loop.
Under heavy queue load the recursion depth could grow unboundedly;
the iterative form has the same behaviour with no stack risk.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

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

Copy link
Copy Markdown

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 refactors the recursive _wait_until_complete method in SRT/netfunnel.py into an iterative while True loop to avoid potential recursion limit issues. The review feedback suggests adding an explicit timeout parameter to the HTTP GET request to prevent the application from hanging indefinitely during high-traffic periods.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread SRT/netfunnel.py
Comment on lines +114 to +117
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Under high-traffic conditions (when NetFunnel is typically active), the server is more likely to experience high load, leading to dropped connections or extremely slow responses. Since requests.get has no default timeout, the call can hang indefinitely, causing the application to freeze. Adding an explicit timeout parameter prevents this.

Suggested change
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
)
resp = self.session.get(
self.NETFUNNEL_URL,
params=params,
timeout=10,
)

@laz- laz- deployed to external June 2, 2026 23:54 — with GitHub Actions Active
@ryanking13

Copy link
Copy Markdown
Owner

Well, I doubt there would be a large number of recursive calls normally. Did you ever face this situation?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants