Skip to content

Commit

Permalink
More clearly abort refused connections downstream
Browse files Browse the repository at this point in the history
Mildly more accurate proxying I think (though less technically correct)
but especially useful because its the error we receive for failed proxy
connections, which will imminently become relevant.
  • Loading branch information
pimterry committed Sep 13, 2022
1 parent 8fad51a commit fe308ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/requests/request-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
}
clientRes.tags.push('passthrough-error:' + e.code);

if (e.code === 'ECONNRESET') {
if (e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED') {
// The upstream socket closed: forcibly close the downstream stream to match
const socket: net.Socket = (clientReq as any).socket;
socket.destroy();
Expand Down
3 changes: 2 additions & 1 deletion test/integration/subscriptions/response-events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ describe("Abort subscriptions", () => {
await server.on('response', (r) => seenResponsePromise.resolve(r));

await server.forAnyRequest().thenPassThrough({
proxyConfig: { proxyUrl: `http://localhost:8901` }
// Wrong port: this connection will fail
proxyConfig: { proxyUrl: `http://localhost:8999` }
});

fetch(server.urlFor("/mocked-endpoint")).catch(() => {});
Expand Down

0 comments on commit fe308ab

Please sign in to comment.