Skip to content

Commit bb26dcf

Browse files
committed
grpc-js: Fix handling of grpc.enable_channelz option
1 parent 78466ac commit bb26dcf

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
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.4.2",
3+
"version": "1.4.3",
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.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ export class Subchannel {
832832
headersString
833833
);
834834
const streamSession = this.session;
835+
let statsTracker: SubchannelCallStatsTracker;
835836
if (this.channelzEnabled) {
836837
this.callTracker.addCallStarted();
837838
callStream.addStatusWatcher(status => {
@@ -851,16 +852,22 @@ export class Subchannel {
851852
}
852853
}
853854
});
854-
callStream.attachHttp2Stream(http2Stream, this, extraFilters, {
855+
statsTracker = {
855856
addMessageSent: () => {
856857
this.messagesSent += 1;
857858
this.lastMessageSentTimestamp = new Date();
858859
},
859860
addMessageReceived: () => {
860861
this.messagesReceived += 1;
861862
}
862-
});
863+
}
864+
} else {
865+
statsTracker = {
866+
addMessageSent: () => {},
867+
addMessageReceived: () => {}
868+
}
863869
}
870+
callStream.attachHttp2Stream(http2Stream, this, extraFilters, statsTracker);
864871
}
865872

866873
/**

packages/grpc-js/test/test-channelz.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,36 @@ describe('Channelz', () => {
286286
});
287287
});
288288
});
289+
});
290+
291+
describe('Disabling channelz', () => {
292+
let testServer: grpc.Server;
293+
let testClient: ServiceClient;
294+
beforeEach((done) => {
295+
testServer = new grpc.Server({'grpc.enable_channelz': 0});
296+
testServer.addService(TestServiceClient.service, testServiceImpl);
297+
testServer.bindAsync('localhost:0', grpc.ServerCredentials.createInsecure(), (error, port) => {
298+
if (error) {
299+
done(error);
300+
return;
301+
}
302+
testServer.start();
303+
testClient = new TestServiceClient(`localhost:${port}`, grpc.credentials.createInsecure(), {'grpc.enable_channelz': 0});
304+
done();
305+
});
306+
});
307+
308+
afterEach(() => {
309+
testClient.close();
310+
testServer.forceShutdown();
311+
});
312+
313+
it('Should still work', (done) => {
314+
const deadline = new Date();
315+
deadline.setSeconds(deadline.getSeconds() + 1);
316+
testClient.unary({}, {deadline}, (error: grpc.ServiceError, value: unknown) => {
317+
assert.ifError(error);
318+
done();
319+
});
320+
});
289321
});

0 commit comments

Comments
 (0)