Skip to content

Commit

Permalink
grpc-js: dont set createConnection when connecting with TLS and witho…
Browse files Browse the repository at this point in the history
…ut a proxy
  • Loading branch information
mrfelton committed Apr 18, 2020
1 parent 2c5a8b1 commit 3eadd5a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/grpc-js/src/subchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,28 @@ export class Subchannel {
};
connectionOptions.servername = sslTargetNameOverride;
}
}
/* In all but the most recent versions of Node, http2.connect does not use
* the options when establishing plaintext connections, so we need to
* establish that connection explicitly. */
connectionOptions.createConnection = (authority, option) => {
if (proxyConnectionResult.socket) {
return proxyConnectionResult.socket;
} else if ('secureContext' in connectionOptions) {
return tls.connect(this.subchannelAddress);
connectionOptions.createConnection = (authority, option) => {
return proxyConnectionResult.socket
? proxyConnectionResult.socket
: tls.connect(this.subchannelAddress)
};
}
/* net.NetConnectOpts is declared in a way that is more restrictive
* than what net.connect will actually accept, so we use the type
* assertion to work around that. */
return net.connect(this.subchannelAddress);
};
} else {
/* In all but the most recent versions of Node, http2.connect does not use
* the options when establishing plaintext connections, so we need to
* establish that connection explicitly. */
connectionOptions.createConnection = (authority, option) => {
if (proxyConnectionResult.socket) {
return proxyConnectionResult.socket;
}
/* net.NetConnectOpts is declared in a way that is more restrictive
* than what net.connect will actually accept, so we use the type
* assertion to work around that. */
return net.connect(this.subchannelAddress);
};
}


connectionOptions = Object.assign(
connectionOptions,
Expand Down

0 comments on commit 3eadd5a

Please sign in to comment.