Skip to content

fix: wait for the function server to accept connections before validating - #224

Draft
taeold wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
taeold:fix/wait-for-server
Draft

taeold wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
taeold:fix/wait-for-server

Conversation

@taeold

@taeold taeold commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Summary

The buildpacks client starts the function container, sleeps for -start-delay (1 second by default, which the reusable buildpack-integration-test.yml workflow also uses), then sends the first request. On a slow runner the server sometimes isn't listening yet, and validation fails with:

validation failure: ... Post "http://localhost:8080": dial tcp [::1]:8080: connect: connection refused

The server logs are empty, because the framework hasn't started.

This shows up regularly in functions-framework-nodejs: 8 of its last 30 Buildpack Integration Test runs failed this way, across Node 18/20/22 and both the http and cloudevent jobs, including scheduled runs on main.

Change

After the existing -start-delay sleep, run() polls localhost:8080 until it accepts a TCP connection, for up to 30 seconds.

  • The existing delay and flag are unchanged, so callers see no difference when the server is already up. The poll returns on the first successful connection.
  • If the server never accepts connections, the client logs a warning and continues. Validation then fails the same way it does today, and the container logs are still collected and uploaded.
  • Only the buildpacks path changes. The local (-cmd) path has the same fixed sleep but I haven't seen it flake, so it's left alone.

Testing

  • go test ./client, go vet ./client, and gofmt -s on the changed files.
  • New unit tests cover a server that's already listening, a server that starts listening after 500 ms, and no server (returns an error after the timeout).

…ting

The buildpacks client starts the function container, sleeps for
-start-delay (1 second by default), then sends the first request. On a slow
CI runner the server sometimes isn't listening yet, and validation fails with
"connection refused" and empty server logs.

After the delay, poll localhost:8080 until it accepts a TCP connection, for up
to 30 seconds. If it never does, log a warning and continue, so validation
still reports the failure and the container logs are still collected.
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