Skip to content

fix(site/e2e): close mock external-auth servers in teardown#26575

Draft
jakehwll wants to merge 2 commits into
mainfrom
jakehwll/devex-413-flake-e2e-externalauthspects
Draft

fix(site/e2e): close mock external-auth servers in teardown#26575
jakehwll wants to merge 2 commits into
mainfrom
jakehwll/devex-413-flake-e2e-externalauthspects

Conversation

@jakehwll

Copy link
Copy Markdown
Contributor

🤖 This PR was written by Coder Agents on behalf of Jake Howell.

The externalAuth e2e suite has been skipped since #17235 because createServer in site/e2e/helpers.ts started an express server but never gave callers a way to close it. On retries or repeated runs, the listener from the previous invocation was still bound to the hardcoded port and the next beforeAll failed with EADDRINUSE, eventually timing out in waitForPort.

createServer now returns a { app, close } pair. The web flow closes in afterAll; the device flow uses try/finally. closeAllConnections() is called before close() so teardown stays bounded if keep-alive connections linger.

The suite remains test.describe.skip for now. A follow-up PR will flip the skip off and watch CI to confirm A is sufficient before any further work.

Refs https://linear.app/codercom/issue/DEVEX-413
Refs coder/internal#356

Decision log

Discussed the full options list with @jakehwll before drafting. Picked option A (minimal teardown) because:

Returning close rather than the raw http.Server encapsulates the closeAllConnections + close choreography so callers don't repeat it. closeAllConnections is optional-chained because it landed in Node 18.2; coder/coder runs newer, but the chain costs nothing.

The device test uses try/finally rather than a shared afterEach to keep per-test state local. The web flow's afterAll mirrors its beforeAll.

createServer now returns a close handle so callers can release the listener after the test. The web flow closes in afterAll; the device flow uses try/finally. This prevents leaked listeners from triggering EADDRINUSE on the next run, the long-standing root cause of the externalAuth.spec.ts flake (coder/internal#356).
@linear-code

linear-code Bot commented Jun 22, 2026

Copy link
Copy Markdown

DEVEX-413

@datadog-coder

This comment has been minimized.

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