Repository navigation
Conversation
…ad of hanging If new Cookie() threw while generating a session (for example maxAge given as a string, directly or from a cookie function), req.session was left without a cookie. The error reached the error handler, but its res.end() then threw in touch(), so the response never completed.
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.
If the cookie options can't be turned into a
Cookie, the request hangs instead of failing:On master,
GET /never gets a response. The client seessocket hang up, and the process logsTypeError: Cannot read properties of undefined (reading 'originalMaxAge').Why:
store.generate()assignsreq.session = new Session(req)beforenew Cookie(options), so when theCookieconstructor throws ("maxAge must be a number or Date"),req.sessionis left without a cookie. The original error does reach the error handler, but the patchedres.end()then callsreq.session.touch(), which readsthis.cookie.originalMaxAgeand throws, so the response is never finished. Since 1.19 cookie options can come from a per-request function, this can't be fully caught when the middleware is created.Fix: if building the cookie throws, remove the half-made
req.sessionbefore rethrowing. The error handler's response then completes normally (500 with "maxAge must be a number or Date", noSet-Cookie). Option order and thecookie(req)call are unchanged.Tests
cookie option/when "cookie" is a function: an Express app whose cookie function returns{ maxAge: '1000' }must answer 500 with the error message and noSet-Cookie. It times out on master (with theoriginalMaxAgeTypeError) and passes here.npm test: 174 passing.eslintclean. HISTORY entry added.Note: #1151 (mine) also touches
store.generate, so whichever lands second will need a small rebase; the two changes are independent.