Skip to content

fix(examples): wait for emulator port to open before executing samples#828

Open
olavloite wants to merge 3 commits into
mainfrom
fix/samples-emulator-flakiness
Open

fix(examples): wait for emulator port to open before executing samples#828
olavloite wants to merge 3 commits into
mainfrom
fix/samples-emulator-flakiness

Conversation

@olavloite

Copy link
Copy Markdown
Collaborator

Resolves race conditions/flakiness in the samples test suite. Previously, startEmulator only checked if the container is running before returning. However, the Spanner emulator process takes some time to initialize and bind to port 9010. If a sample executes immediately, it fails with a 'connection reset by peer' error. Added a TCP Dial check loop to ensure port 9010 is open before returning from startEmulator.

@olavloite olavloite requested a review from a team as a code owner June 11, 2026 14:40

@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 improves the emulator startup logic in examples/emulator_runner.go by waiting for port 9010 to be open and accepting connections, rather than just checking if the container is running. Feedback suggests using 127.0.0.1 instead of localhost to avoid dual-stack DNS resolution issues, and replacing <-time.After with time.Sleep to prevent unnecessary timer allocations within the loop.

Comment thread examples/emulator_runner.go Outdated
Comment thread examples/emulator_runner.go Outdated
@olavloite olavloite force-pushed the fix/samples-emulator-flakiness branch from a9b4b26 to c531981 Compare June 12, 2026 07:28
@olavloite

Copy link
Copy Markdown
Collaborator Author

LGTM. Checking TCP port 9010 before returning from startEmulator ensures that the emulator is fully ready to accept connections before running samples, preventing connection errors.

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.

1 participant