Skip to content

HttpMiddleware.logger logs an upgraded WebSocket request with the handler's status, not 101 #8730

Closed

Description

@MajorBreakfast

What version of Effect is running?

effect 4.0.0, @effect/platform-node 4.0.0

What steps can reproduce the bug?

A WebSocket route is logged when the socket closes, with the status of the response the handler returns.

import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
import { Effect, Layer, Stream } from "effect"
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/http"
import { Socket } from "effect/socket"
import { createServer } from "node:http"

const SocketLayer = HttpRouter.add("GET", "/socket", Effect.gen(function*() {
  const socket = yield* (yield* HttpServerRequest.HttpServerRequest).upgrade
  yield* Stream.runDrain(Socket.toStream(socket)).pipe(Effect.ignore)
  return HttpServerResponse.empty()
}))

Effect.gen(function*() {
  yield* Layer.build(HttpRouter.serve(SocketLayer).pipe(Layer.provide(NodeHttpServer.layer(createServer, { port: 3998 }))))
  yield* Effect.promise(() => new Promise<void>((resolve) => {
    const ws = new WebSocket("ws://127.0.0.1:3998/socket")
    ws.onopen = () => setTimeout(() => ws.close(1000), 200)
    ws.onclose = () => resolve()
  }))
  yield* Effect.sleep("300 millis")
}).pipe(Effect.scoped, Effect.runPromise)

What is the expected behavior?

INFO http.span=215ms: Sent HTTP response { 'http.method': 'GET', 'http.url': '/socket', 'http.status': 101 }

What do you see instead?

INFO http.span=215ms: Sent HTTP response { 'http.method': 'GET', 'http.url': '/socket', 'http.status': 204 }

Additional information

The client received 101. The logged 204 is the status of the HttpServerResponse.empty() the handler returns after the socket closes, which is never sent.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/101

Activity

  1. added
    bug
    on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions