fix(request): use PassThrough as socket for IncomingMessage#714
Open
alex-all3dp wants to merge 1 commit intoCodeGenieApp:mainlinefrom
Open
fix(request): use PassThrough as socket for IncomingMessage#714alex-all3dp wants to merge 1 commit intoCodeGenieApp:mainlinefrom
alex-all3dp wants to merge 1 commit intoCodeGenieApp:mainlinefrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@codegenie/serverless-express>= 4.16.0 with Express 5 throwsTypeError: ee.on is not a functionwhenever a request reaches Express'sfinalhandler(e.g. unmatched routes). Reported in #698; still present in v5.0.0.Stack from production:
Root cause
ServerlessRequest(src/request.js) extendshttp.IncomingMessageand passes a plain object as the socket. When Express 5'sfinalhandlerreaches an unmatched route and the request body wasn't consumed (typical for GETs), it callsonFinished(req), which usesee-firstto attacherrorandcloselisteners onreq.socket. The plain object has no.on, so it throws.Fix
Use a
PassThroughstream as the socket. PassThrough inherits the EventEmitter interface via Duplex/Stream, so.on,.once,.emit, and.removeListenerare all present. Theend/destroyFunction.prototypestubs are dropped since PassThrough provides real implementations.This is the same fix that landed upstream in
dougmoscrop/serverless-http#306(merged Sep 2025), the library this file was forked from per the attribution comment at the top.Closes #698