Repository navigation
Conversation
…shes A request built against the shared server did not hold it open until end(), so another request finishing in between closed the server and the late send dispatched at a dead address. fixes forwardemail#909
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.
Fixes #909
Building a request against the shared server calls
serverAddress(), which listens, butstate.pendingis only incremented inend(). An inner request that finishes first seespending === 0, closes the server, and deletes the state. The outerend()then dispatches at the closed address. On 7.3.1 that isTypeError: Cannot read properties of null (reading 'address')whenserver.address()is null. If the URL already contains the port, the same case isECONNREFUSED.pendingis not incremented at construction. ATestthat is built and never sent would otherwise keep the port after every other request finished. Whenend()finds the shared server it bound already closed, or closing, it listens again on127.0.0.1with an ephemeral port, waits forlistening, rewrites the URL with the current port, and dispatches. Requests that have already calledend()still share one state, and the last one closes the server. A server the caller passed in already listening is left alone.A
Testthat is built and neverend()ed no longer blocks a later request from closing the server. If nothing in the process callsend(), the server stays listening. That is the existing behavior: construction callslisten(), and only anend()that dropspendingto 0 callsclose().Testing
npx mocha --exit --require should --reporter spec --check-leaks test/supertest.js --grep "shared server late dispatch": before this change,request(server)andrequest.agent(server)failed with the TypeError (0 passing, 2 failing). After, 4 passing, including the case where the port is already in the URLnpm test: eslint clean, mocha 141 passing