Skip to content

Commit f29e99d

Browse files
authored
Merge pull request #2336 from murgatroid99/grpc-js_transport_garbage_collection
grpc-js: Hold a reference to transport in SubchannelCall
2 parents 0081d24 + 6d98dc5 commit f29e99d

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

packages/grpc-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.8.5",
3+
"version": "1.8.6",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

packages/grpc-js/src/subchannel-call.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { LogVerbosity } from './constants';
2626
import { ServerSurfaceCall } from './server-call';
2727
import { Deadline } from './deadline';
2828
import { InterceptingListener, MessageContext, StatusObject, WriteCallback } from './call-interface';
29-
import { CallEventTracker } from './transport';
29+
import { CallEventTracker, Transport } from './transport';
3030

3131
const TRACER_NAME = 'subchannel_call';
3232

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

108-
private disconnectListener: () => void;
109-
110108
private internalError: SystemError | null = null;
111109

112110
constructor(
113111
private readonly http2Stream: http2.ClientHttp2Stream,
114112
private readonly callEventTracker: CallEventTracker,
115113
private readonly listener: SubchannelCallInterceptingListener,
116-
private readonly peerName: string,
114+
private readonly transport: Transport,
117115
private readonly callId: number
118116
) {
119-
this.disconnectListener = () => {
120-
this.endCall({
121-
code: Status.UNAVAILABLE,
122-
details: 'Connection dropped',
123-
metadata: new Metadata(),
124-
});
125-
};
126117
http2Stream.on('response', (headers, flags) => {
127118
let headersString = '';
128119
for (const header of Object.keys(headers)) {
@@ -475,7 +466,7 @@ export class Http2SubchannelCall implements SubchannelCall {
475466
}
476467

477468
getPeer(): string {
478-
return this.peerName;
469+
return this.transport.getPeerName();
479470
}
480471

481472
getCallNumber(): number {

packages/grpc-js/src/transport.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface TransportDisconnectListener {
6565

6666
export interface Transport {
6767
getChannelzRef(): SocketRef;
68+
getPeerName(): string;
6869
createCall(metadata: Metadata, host: string, method: string, listener: SubchannelCallInterceptingListener, subchannelCallStatsTracker: Partial<CallEventTracker>): SubchannelCall;
6970
addDisconnectListener(listener: TransportDisconnectListener): void;
7071
shutdown(): void;
@@ -448,7 +449,7 @@ class Http2Transport implements Transport {
448449
}
449450
}
450451
}
451-
call = new Http2SubchannelCall(http2Stream, eventTracker, listener, this.subchannelAddressString, getNextCallNumber());
452+
call = new Http2SubchannelCall(http2Stream, eventTracker, listener, this, getNextCallNumber());
452453
this.addActiveCall(call);
453454
return call;
454455
}
@@ -457,6 +458,10 @@ class Http2Transport implements Transport {
457458
return this.channelzRef;
458459
}
459460

461+
getPeerName() {
462+
return this.subchannelAddressString;
463+
}
464+
460465
shutdown() {
461466
this.session.close();
462467
}

0 commit comments

Comments
 (0)