Skip to content

Commit

Permalink
fix `Something wrong with keep-alive agent sockets - networking hangs…
Browse files Browse the repository at this point in the history
… on OS level` (close DevExpress#2149)
  • Loading branch information
LavrovArtem committed Jan 24, 2020
1 parent 2a5ecc4 commit 2886d03
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/request-pipeline/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default class RequestPipelineContext {
mock: ResponseMock;
isSameOriginPolicyFailed: boolean = false;
windowId?: string;
aborted = false;

constructor (req: http.IncomingMessage, res: http.ServerResponse | net.Socket, serverInfo: ServerInfo) {
this.serverInfo = serverInfo;
Expand Down
12 changes: 11 additions & 1 deletion src/request-pipeline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const stages = [
if (!ctx.isWebSocket)
return;

// NOTE: The `aborted` property of http.IncomingMessage added in v10.1.0 node version
// because of this we using this workaround
ctx.req.on('aborted', () => {
ctx.aborted = true;
});

ctx.res.on('error', e => {
// @ts-ignore
if (e.code === 'ECONNRESET' && !ctx.mock) {
Expand Down Expand Up @@ -125,8 +131,12 @@ const stages = [
await callOnResponseEventCallbackWithBodyForNonProcessedRequest(ctx, onResponseEventDataWithBody);
else if (onResponseEventDataWithoutBody.length)
await callOnResponseEventCallbackWithoutBodyForNonProcessedResource(ctx, onResponseEventDataWithoutBody);
else
else if (ctx.aborted)
ctx.destRes.destroy();
else {
ctx.destRes.pipe(ctx.res);
ctx.res.on('close', () => ctx.destRes.destroy());
}
}

// NOTE: sets 60 minutes timeout for the "event source" requests instead of 2 minutes by default
Expand Down
2 changes: 1 addition & 1 deletion src/request-pipeline/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function sendRequest (ctx: RequestPipelineContext) {
req.on('response', (res: http.IncomingMessage | FileStream) => {
if (ctx.isWebSocketConnectionReset) {
res.destroy();

resolve();
return;
}

ctx.destRes = res;
Expand Down

0 comments on commit 2886d03

Please sign in to comment.