grpc-js: Make call and stream tracking more consistent

This commit is contained in:
Michael Lumish 2023-01-12 09:47:19 -08:00
parent b342001b38
commit fade30bd0a
2 changed files with 2 additions and 3 deletions

View File

@ -198,6 +198,7 @@ export class Http2SubchannelCall implements SubchannelCall {
* we can bubble up the error message from that event. */ * we can bubble up the error message from that event. */
process.nextTick(() => { process.nextTick(() => {
this.trace('HTTP/2 stream closed with code ' + http2Stream.rstCode); this.trace('HTTP/2 stream closed with code ' + http2Stream.rstCode);
this.callEventTracker.onStreamEnd(this.finalStatus?.code === Status.OK);
/* If we have a final status with an OK status code, that means that /* If we have a final status with an OK status code, that means that
* we have received all of the messages and we have processed the * we have received all of the messages and we have processed the
* trailers and the call completed successfully, so it doesn't matter * trailers and the call completed successfully, so it doesn't matter
@ -288,7 +289,6 @@ export class Http2SubchannelCall implements SubchannelCall {
); );
this.internalError = err; this.internalError = err;
} }
this.callEventTracker.onStreamEnd(false);
}); });
} }
@ -403,7 +403,6 @@ export class Http2SubchannelCall implements SubchannelCall {
} }
private handleTrailers(headers: http2.IncomingHttpHeaders) { private handleTrailers(headers: http2.IncomingHttpHeaders) {
this.callEventTracker.onStreamEnd(true);
let headersString = ''; let headersString = '';
for (const header of Object.keys(headers)) { for (const header of Object.keys(headers)) {
headersString += '\t\t' + header + ': ' + headers[header] + '\n'; headersString += '\t\t' + header + ': ' + headers[header] + '\n';

View File

@ -420,6 +420,7 @@ class Http2Transport implements Transport {
}, },
onCallEnd: status => { onCallEnd: status => {
subchannelCallStatsTracker.onCallEnd?.(status); subchannelCallStatsTracker.onCallEnd?.(status);
this.removeActiveCall(call);
}, },
onStreamEnd: success => { onStreamEnd: success => {
if (success) { if (success) {
@ -427,7 +428,6 @@ class Http2Transport implements Transport {
} else { } else {
this.streamTracker.addCallFailed(); this.streamTracker.addCallFailed();
} }
this.removeActiveCall(call);
subchannelCallStatsTracker.onStreamEnd?.(success); subchannelCallStatsTracker.onStreamEnd?.(success);
} }
} }