pingdotgg / pingdotgg/t3code

[Bug]: Requests that arrive during server startup are never answered (socket accepts, handler not attached yet)

Open
#12,215 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

accepted bug upstream via-triage
Dominant language
TypeScript
Stars
23k
Forks
5.9k
Avg merge
11h 14m
Merged PRs (30d)
357

Description

Before submitting
  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.
Area

apps/server

Steps to reproduce

Uses a throwaway data dir and a spare port, so no existing state is touched:

H=$(mktemp -d); export HOME=$H T3CODE_HOME=$H/.t3
t3 serve --host 127.0.0.1 --port 38775 > $H/log 2>&1 &

# 1. wait until the port accepts TCP connections
until (exec 3<>/dev/tcp/127.0.0.1/38775) 2>/dev/null; do sleep 0.05; done

# 2. send a request right away (before "T3 Code server is ready")
curl -s -o /dev/null -w "early: %{http_code} %{time_total}s\n" --max-time 45 http://127.0.0.1:38775/ &

# 3. wait for readiness, then send a second request
until grep -q "server is ready" $H/log; do sleep 0.1; done
curl -s -o /dev/null -w "late:  %{http_code} %{time_total}s\n" --max-time 5 http://127.0.0.1:38775/
wait
Expected behavior

A request that connects before the server is ready is either held and served once the app is ready, or rejected quickly (e.g. connection refused or 503 + Retry-After). The port should not accept connections it will never answer.

Actual behavior

The port accepts connections roughly 0.5–1s before the HTTP handler is attached. Requests sent in that window never get a response, not even after the server is ready. The socket stays open until the client gives up, so a client with no timeout hangs forever. In a NixOS VM test, a plain curl hung for the full 1h test timeout.

Requests sent after "T3 Code server is ready" are fine (200 in ~7ms).

Cause, as far as I can tell: in @effect/platform-node (NodeHttpServer.make, 4.0.0-beta.103), server.listen() runs while the layer is being built, but server.on("request", handler) / server.on("upgrade", ...) are only registered later in serve(httpApp). The other server startup layers (SQLite migrations, provider setup, …) run in between. Node's http.Server emits request with no listener, so the request is silently dropped.

Possible fixes: register the request/upgrade listeners before listen(), or answer 503 Retry-After until serve() runs, or bring up the HTTP server layer after the heavy startup layers. The root cause is probably worth a matching issue in Effect-TS/effect-smol.

Impact

Minor bug or occasional failure

Version or commit

t3 v0.0.40 (@effect/platform-node 4.0.0-beta.103)

Environment

NixOS 26.11, Linux 7.2.4, Node 24.20.0, t3 serve (web mode, headless)

Logs or stack traces
late:  200 0.007279s
early: 000 45.001325s

# server log: nothing is logged for the early request
[14:32:13.680] INFO (#409): Listening on http://127.0.0.1:38775
T3 Code server is ready.
Screenshots, recordings, or supporting files

No response

Workaround

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in apps/server by tracing startup through @effect/platform-node's NodeHttpServer.make and serve(httpApp), focusing on when request and upgrade listeners are registered relative to server.listen(). Run the provided startup reproduction; done means requests arriving before readiness are served or rejected promptly instead of remaining open indefinitely, while requests after readiness still succeed.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.