-
Notifications
You must be signed in to change notification settings - Fork 180
Add orchestrator proxy retries to handle port forwarding delay #1350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Code42Cate
commented
Oct 13, 2025
djeebus
reviewed
Oct 13, 2025
djeebus
approved these changes
Oct 13, 2025
ValentaTomas
approved these changes
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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.
Problem
When a process binds to localhost inside a sandbox, envd scans every 1s to detect it and starts socat to forward the port to the host IP (169.254.0.21). This creates a race condition where HTTP requests can arrive before forwarding is active, causing immediate connection failures.
Solution
Added retry logic in the proxy's DialContext with linear backoff:
Behavior
Best case: Port already forwarded → immediate success (0ms)
Average: Request arrives mid-scan → 1-2 retries, ~300ms delay
Worst case (success): Request arrives just before scan → 4-5 retries, ~1000ms delay
Worst case (failure): Port doesn't exist → ~1000ms then error
Testing
Added TestProxyRetriesOnDelayedBackendStartup that simulates a 300ms backend startup delay. Test passes with retries, fails without them. You can verify that behavior by reducing the attempts to 1. The tests will then fail
Note
Adds linear-backoff connection retries to proxy DialContext (5 for orchestrator, 1 for client) and updates pool/proxy APIs and tests, including a delayed-backend startup test.
MaxConnectionAttemptsand constantsClientProxyRetries(1) andSandboxProxyRetries(5).reverseproxy.New(port, maxConnectionAttempts, idleTimeout, getDestination)and pass attempts to pool.pool/client.goDialContextwith linear backoff (100–400ms) and context-aware exits.pool.New(maxClientConns, maxConnectionAttempts, idleTimeout)and propagate attempts inProxyPool.GettonewProxyClient.SandboxProxyRetries; client usesClientProxyRetries.TestProxyRetriesOnDelayedBackendStartupto validate retry behavior.require.NoError.Written by Cursor Bugbot for commit 95393d6. This will update automatically on new commits. Configure here.