Skip to content

Fastify Websocket with @fastify/vite #19907

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

Open
ShaharIlany opened this issue May 25, 2025 · 0 comments
Open

Fastify Websocket with @fastify/vite #19907

ShaharIlany opened this issue May 25, 2025 · 0 comments
Labels
bug Something isn't working bun --hot ecosystem Something that relates to package or framework compatibility regression web:websocket

Comments

@ShaharIlany
Copy link

ShaharIlany commented May 25, 2025

What version of Bun is running?

1.2.14

What platform is your computer?

Darwin 24.5.0 arm64 arm

What steps can reproduce the bug?

Following the fix in #18685, a new warning appears when using Fastify with both @fastify/websocket and @fastify/vite.

Reproduction Steps:

  1. Run the server using bun dev
  2. Open web browser and go to localhost:3000
  3. Trigger a reload by:
    • Saving server.ts (with --watch)
    • Or stopping and restarting the server
  4. Observe the console output:
[21:28:26 UTC] INFO: Server listening at http://127.0.0.1:3000
[21:28:26 UTC] INFO: Server listening at http://192.168.1.221:3000
[21:28:27 UTC] WARN: Reply was already sent, did you forget to "return reply" in "/" (GET)?
    reqId: "req-1"
    err: {
      "type": "FastifyError",
      "message": "Reply was already sent, did you forget to \"return reply\" in \"/\" (GET)?",
      "stack":
          Error
              at <anonymous> (...../test/node_modules/fastify/lib/reply.js:134:30)
              at preHandlerCallbackInner (...../test/node_modules/fastify/lib/handleRequest.js:169:13)
              at preHandlerCallback (...../test/node_modules/fastify/lib/handleRequest.js:129:5)
              at validationCompleted (...../test/node_modules/fastify/lib/handleRequest.js:119:5)
              at preValidationCallback (...../test/node_modules/fastify/lib/handleRequest.js:96:5)
              at handler (...../test/node_modules/fastify/lib/handleRequest.js:73:7)
              at handleRequest (...../test/node_modules/fastify/lib/handleRequest.js:29:5)
              at runPreParsing (...../test/node_modules/fastify/lib/route.js:571:19)
              at next (...../test/node_modules/fastify/lib/hooks.js:236:9)
              at handleResolve (...../test/node_modules/fastify/lib/hooks.js:253:7)
      "code": "FST_ERR_REP_ALREADY_SENT",
      "name": "FastifyError",
      "statusCode": 500
    }

Notes:

  • Does not occur on Bun v1.2.5
  • Reproduced consistently on Bun v1.2.9 to v1.2.14
  • The issue started after the websocket bug fix introduced post v1.2.6

Suspected Cause
This appears to be a side effect of recent changes to Bun’s HTTP upgrade handling or module caching related to WebSocket hot reload behavior. Possibly, @fastify/vite is trying to serve a response to an already handled WebSocket upgrade route.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

Source code for reproduction:
https://github.com/ShaharIlany/bun-fastify-bug

@ShaharIlany ShaharIlany added bug Something isn't working needs triage labels May 25, 2025
@github-actions github-actions bot added regression web:websocket ecosystem Something that relates to package or framework compatibility bun --hot and removed needs triage labels May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun --hot ecosystem Something that relates to package or framework compatibility regression web:websocket
Projects
None yet
Development

No branches or pull requests

1 participant