TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
871 stars 229 forks source link

fix: should close both connections when client disconnects #270

Closed mxschmitt closed 2 months ago

mxschmitt commented 5 months ago

The order was the following:

CONNECT spocs.getpocket.com:443 HTTP/1.1  +26ms
proxy target spocs.getpocket.com:443 "connect" event +17ms
proxy ← ← ← HTTP request spocs.getpocket.com:443 socket "end" event +541ms
proxy ← ← ← HTTP request spocs.getpocket.com:443 socket "error" event:
proxy ← ← ← Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:952:11)
at Socket._write (node:net:964:8)
at writeOrBuffer (node:internal/streams/writable:447:12)
at _write (node:internal/streams/writable:389:10)
at Socket.Writable.write (node:internal/streams/writable:393:10)
at Socket.ondata (node:internal/streams/readable:817:22)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:376:12)
at readableAddChunk (node:internal/streams/readable:349:9)
at Socket.Readable.push (node:internal/streams/readable:286:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) +51ms
proxy ← ← ← HTTP request spocs.getpocket.com:443 socket "close" event +0ms
proxy ↓ ↓ ↓ proxy target spocs.getpocket.com:443 "end" event +57ms
proxy ↓ ↓ ↓ proxy target spocs.getpocket.com:443 "close" event +1ms

Before the change in the library it failed with:

  ● proxy › should close both connections when client disconnects

    expect(received).toEqual(expected) // deep equality

    Expected: "closed"
    Received: "writeOnly"

      225 |             ])
      226 |             expect(targetRequest.readyState).toEqual("closed")
    > 227 |             expect(serverSocket.readyState).toEqual("closed")
          |                                             ^
      228 |     });
      229 | });
      230 |

      at Object.<anonymous> (test/test.ts:227:35)

Fixes https://github.com/TooTallNate/proxy-agents/issues/267. Relates https://github.com/microsoft/playwright/issues/28701.

changeset-bot[bot] commented 5 months ago

⚠️ No Changeset found

Latest commit: ba932acb5ad397f55787ef184bfdc482f3e520ea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
proxy-agents ✅ Ready (Inspect) Visit Preview Jan 16, 2024 0:48am
mxschmitt commented 5 months ago

@TooTallNate PTAL, I'm kinda struggling creating a reliable test for it which reproduces the problem we had, but I feel like this code addition and test seems reasonable. Would appreciate if you could take a look, Thanks!