Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests for Node.js clients and fix hanging requests #619

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ testconnectpackage: $(BUILD)/connect
npm run -w packages/connect jasmine

.PHONY: testconnectnodepackage
testconnectnodepackage: $(BUILD)/connect-node
npm run -w packages/connect-node jasmine
testconnectnodepackage: $(BIN)/node16 $(BIN)/node18 $(BIN)/node19 $(BIN)/node20 $(BUILD)/connect-node
cd packages/connect-node && PATH="$(abspath $(BIN)):$(PATH)" node16 --trace-warnings ../../node_modules/.bin/jasmine --config=jasmine.json
cd packages/connect-node && PATH="$(abspath $(BIN)):$(PATH)" node18 --trace-warnings ../../node_modules/.bin/jasmine --config=jasmine.json
cd packages/connect-node && PATH="$(abspath $(BIN)):$(PATH)" node19 --trace-warnings ../../node_modules/.bin/jasmine --config=jasmine.json
cd packages/connect-node && PATH="$(abspath $(BIN)):$(PATH)" node20 --trace-warnings ../../node_modules/.bin/jasmine --config=jasmine.json

.PHONY: testnode
testnode: $(BIN)/node16 $(BIN)/node18 $(BIN)/node19 $(BIN)/node20 $(BUILD)/connect-node-test
Expand Down
83 changes: 82 additions & 1 deletion packages/connect-node/src/node-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export function connectErrorFromNodeReason(reason: unknown): ConnectError {
} else if (
chain.some(
(p) =>
p.code == "ERR_STREAM_DESTROYED" || p.code == "ERR_HTTP2_INVALID_STREAM"
p.code == "ERR_STREAM_DESTROYED" ||
p.code == "ERR_HTTP2_INVALID_STREAM" ||
p.code == "ECONNRESET"
)
) {
// A handler whose stream is suddenly destroyed usually means the client
Expand Down Expand Up @@ -111,3 +113,82 @@ export function getNodeErrorProps(reason: unknown): {
}
return props;
}

/**
* Returns a ConnectError for a HTTP/2 error code.
*/
export function connectErrorFromH2ResetCode(
Comment on lines +117 to +120
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the bug fixes.

This is a continuation of #552, where we closed a cancelled request with the HTTP/2 code CANCEL. Now we also interpret HTTP/2 RST codes received by the client correctly.

rstCode: number
): ConnectError | undefined {
switch (rstCode) {
case H2Code.PROTOCOL_ERROR:
case H2Code.INTERNAL_ERROR:
case H2Code.FLOW_CONTROL_ERROR:
case H2Code.SETTINGS_TIMEOUT:
case H2Code.FRAME_SIZE_ERROR:
case H2Code.COMPRESSION_ERROR:
case H2Code.CONNECT_ERROR:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.Internal
);
case H2Code.REFUSED_STREAM:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.Unavailable
);
case H2Code.CANCEL:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.Canceled
);
case H2Code.ENHANCE_YOUR_CALM:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.ResourceExhausted
);
case H2Code.INADEQUATE_SECURITY:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.PermissionDenied
);
case H2Code.HTTP_1_1_REQUIRED:
return new ConnectError(
`http/2 stream closed with RST code ${
H2Code[rstCode]
} (0x${rstCode.toString(16)})`,
Code.PermissionDenied
);
case H2Code.STREAM_CLOSED:
default:
// Intentionally not mapping STREAM_CLOSED (0x5), see https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#errors
break;
}
return undefined;
}

export enum H2Code {
PROTOCOL_ERROR = 0x1,
INTERNAL_ERROR = 0x2,
FLOW_CONTROL_ERROR = 0x3,
SETTINGS_TIMEOUT = 0x4,
STREAM_CLOSED = 0x5,
FRAME_SIZE_ERROR = 0x6,
REFUSED_STREAM = 0x7,
CANCEL = 0x8,
COMPRESSION_ERROR = 0x9,
CONNECT_ERROR = 0xa,
ENHANCE_YOUR_CALM = 0xb,
INADEQUATE_SECURITY = 0xc,
HTTP_1_1_REQUIRED = 0xd,
}
Loading