Skip to content

Commit

Permalink
grpc-js: Hold a reference to transport in SubchannelCall
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Jan 25, 2023
1 parent 0081d24 commit 6d98dc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
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.8.5",
"version": "1.8.6",
"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
15 changes: 3 additions & 12 deletions packages/grpc-js/src/subchannel-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { LogVerbosity } from './constants';
import { ServerSurfaceCall } from './server-call';
import { Deadline } from './deadline';
import { InterceptingListener, MessageContext, StatusObject, WriteCallback } from './call-interface';
import { CallEventTracker } from './transport';
import { CallEventTracker, Transport } from './transport';

const TRACER_NAME = 'subchannel_call';

Expand Down Expand Up @@ -105,24 +105,15 @@ export class Http2SubchannelCall implements SubchannelCall {
// This is populated (non-null) if and only if the call has ended
private finalStatus: StatusObject | null = null;

private disconnectListener: () => void;

private internalError: SystemError | null = null;

constructor(
private readonly http2Stream: http2.ClientHttp2Stream,
private readonly callEventTracker: CallEventTracker,
private readonly listener: SubchannelCallInterceptingListener,
private readonly peerName: string,
private readonly transport: Transport,
private readonly callId: number
) {
this.disconnectListener = () => {
this.endCall({
code: Status.UNAVAILABLE,
details: 'Connection dropped',
metadata: new Metadata(),
});
};
http2Stream.on('response', (headers, flags) => {
let headersString = '';
for (const header of Object.keys(headers)) {
Expand Down Expand Up @@ -475,7 +466,7 @@ export class Http2SubchannelCall implements SubchannelCall {
}

getPeer(): string {
return this.peerName;
return this.transport.getPeerName();
}

getCallNumber(): number {
Expand Down
7 changes: 6 additions & 1 deletion packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface TransportDisconnectListener {

export interface Transport {
getChannelzRef(): SocketRef;
getPeerName(): string;
createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener, subchannelCallStatsTracker: Partial<CallEventTracker>): SubchannelCall;
addDisconnectListener(listener: TransportDisconnectListener): void;
shutdown(): void;
Expand Down Expand Up @@ -448,7 +449,7 @@ class Http2Transport implements Transport {
}
}
}
call = new Http2SubchannelCall(http2Stream, eventTracker, listener, this.subchannelAddressString, getNextCallNumber());
call = new Http2SubchannelCall(http2Stream, eventTracker, listener, this, getNextCallNumber());
this.addActiveCall(call);
return call;
}
Expand All @@ -457,6 +458,10 @@ class Http2Transport implements Transport {
return this.channelzRef;
}

getPeerName() {
return this.subchannelAddressString;
}

shutdown() {
this.session.close();
}
Expand Down

0 comments on commit 6d98dc5

Please sign in to comment.