NodeHttpIncomingMessage.remoteAddress throws after client disconnect clears socket
What happened
With @effect/[email protected], an HTTP request fiber can read HttpServerRequest.remoteAddress after a Node client disconnect has cleared the request socket. NodeHttpIncomingMessage.remoteAddress then throws a defect instead of returning Option.none():
TypeError: Cannot read properties of null (reading 'remoteAddress')
at NodeHttpIncomingMessage.js:58
at HttpMiddleware.js:170
The late read can occur from middleware/finalization after an abort, even when application handling is otherwise interruption-safe.
Current code
get remoteAddress() {
return this.remoteAddressOverride ?? Option.fromNullishOr(this.source.socket.remoteAddress)
}
Node types declare IncomingMessage.socket as non-null, but Node can clear it during disconnect cleanup before a late getter read.
Suggested change
get remoteAddress() {
return this.remoteAddressOverride ?? Option.fromNullishOr(this.source.socket?.remoteAddress)
}
This would preserve the getter's Option<string> contract when the live socket is no longer present. Callers that require the accepted peer for the full request lifetime should still snapshot it at accept time and pass remoteAddressOverride.
Reproduction shape
- Start a
NodeHttpServer.makeHandlerrequest whose Effect remains alive briefly after the response/request closes. - Send a partial request and destroy the client socket.
- After Node has cleared the incoming request's socket, read
HttpServerRequest.remoteAddressfrom an uninterruptible finalizer or late middleware step. - Observe the
TypeErrorabove rather thanOption.none().
Environment: Node 22, [email protected], @effect/[email protected].