Skip to content

grpc-js: Fix the final proxy bugs #1381

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

Merged
merged 2 commits into from
Apr 22, 2020
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
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
3 changes: 2 additions & 1 deletion packages/grpc-js/src/channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
}

_getConnectionOptions(): ConnectionOptions | null {
return this.connectionOptions;
// Copy to prevent callers from mutating this.connectionOptions
return { ...this.connectionOptions };
}
_isSecure(): boolean {
return true;
Expand Down
30 changes: 20 additions & 10 deletions packages/grpc-js/src/http_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export function mapProxyName(
extraOptions['grpc.http_connect_creds'] = proxyInfo.creds;
}
return {
target: {
target: {
scheme: 'dns',
path: proxyInfo.address
path: proxyInfo.address,
},
extraOptions: extraOptions,
};
Expand Down Expand Up @@ -207,23 +207,33 @@ export function getProxiedConnection(
' through proxy ' +
proxyAddressString
);
resolve({
socket,
realTarget: parsedTarget,
});
if ('secureContext' in connectionOptions) {
/* The proxy is connecting to a TLS server, so upgrade this socket
* connection to a TLS connection.
* This is a workaround for https://github.com/nodejs/node/issues/32922
* See https://github.com/grpc/grpc-node/pull/1369 for more info. */
const cts = tls.connect({
...connectionOptions,
host: getDefaultAuthority(parsedTarget),
const remoteHost = getDefaultAuthority(parsedTarget);

const cts = tls.connect(
{
host: remoteHost,
servername: remoteHost,
socket: socket,
}, () => {
...connectionOptions,
},
() => {
trace(
'Successfully established a TLS connection to ' +
options.path +
' through proxy ' +
proxyAddressString
);
resolve({ socket: cts, realTarget: parsedTarget });
}
);
cts.on('error', () => {
reject();
});
} else {
resolve({
socket,
Expand Down
9 changes: 5 additions & 4 deletions packages/grpc-js/src/subchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,11 @@ export class Subchannel {
};
}

connectionOptions = Object.assign(
connectionOptions,
this.subchannelAddress
);
connectionOptions = {
...connectionOptions,
...this.subchannelAddress,
};

/* http2.connect uses the options here:
* https://github.com/nodejs/node/blob/70c32a6d190e2b5d7b9ff9d5b6a459d14e8b7d59/lib/internal/http2/core.js#L3028-L3036
* The spread operator overides earlier values with later ones, so any port
Expand Down