Skip to content
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

grpc-js: Hold a reference to transport in SubchannelCall #2336

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.
Jump to
Jump to file
Failed to load files.
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.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