grpc-js: commenting working for node issue 32922

This commit is contained in:
Tom Kirkpatrick 2020-04-19 19:58:56 +02:00
parent 11965fb0af
commit b9e84f499f
No known key found for this signature in database
GPG Key ID: 72203A8EC5967EA8
2 changed files with 15 additions and 9 deletions

View File

@ -22,9 +22,9 @@ import { getDefaultAuthority } from './resolver';
import { parseTarget } from './resolver-dns'; import { parseTarget } from './resolver-dns';
import { Socket } from 'net'; import { Socket } from 'net';
import * as http from 'http'; import * as http from 'http';
import * as http2 from 'http2';
import * as tls from 'tls'; import * as tls from 'tls';
import * as logging from './logging'; import * as logging from './logging';
import { SecureClientSessionOptions } from 'http2'
import { import {
SubchannelAddress, SubchannelAddress,
isTcpSubchannelAddress, isTcpSubchannelAddress,
@ -161,7 +161,7 @@ export interface ProxyConnectionResult {
export function getProxiedConnection( export function getProxiedConnection(
address: SubchannelAddress, address: SubchannelAddress,
channelOptions: ChannelOptions, channelOptions: ChannelOptions,
connectionOptions: http2.SecureClientSessionOptions connectionOptions: SecureClientSessionOptions
): Promise<ProxyConnectionResult> { ): Promise<ProxyConnectionResult> {
if (!('grpc.http_connect_target' in channelOptions)) { if (!('grpc.http_connect_target' in channelOptions)) {
return Promise.resolve<ProxyConnectionResult>({}); return Promise.resolve<ProxyConnectionResult>({});
@ -206,9 +206,11 @@ export function getProxiedConnection(
' through proxy ' + ' through proxy ' +
proxyAddressString proxyAddressString
); );
// The proxy is connecting to a TLS server, so upgrade
// this socket connection to a TLS connection.
if ('secureContext' in connectionOptions) { 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({ const cts = tls.connect({
...connectionOptions, ...connectionOptions,
host: getDefaultAuthority(realTarget), host: getDefaultAuthority(realTarget),

View File

@ -312,15 +312,15 @@ export class Subchannel {
connectionOptions.createConnection = (authority, option) => { connectionOptions.createConnection = (authority, option) => {
if (proxyConnectionResult.socket) { if (proxyConnectionResult.socket) {
return proxyConnectionResult.socket; return proxyConnectionResult.socket;
} else {
/* 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);
} }
/* 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 = Object.assign(
connectionOptions, connectionOptions,
this.subchannelAddress this.subchannelAddress
@ -416,6 +416,10 @@ export class Subchannel {
} }
private startConnectingInternal() { private startConnectingInternal() {
/* Pass connection options through to the proxy so that it's able to
* upgrade it's connection to support tls if needed.
* 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 connectionOptions: http2.SecureClientSessionOptions = const connectionOptions: http2.SecureClientSessionOptions =
this.credentials._getConnectionOptions() || {}; this.credentials._getConnectionOptions() || {};