Skip to content

Commit d015d1c

Browse files
authored
Merge pull request #907 from cjihrig/session
grpc-js: destroy connections when session begins
2 parents 1e03eae + 31bcaed commit d015d1c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/grpc-js/src/channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ export class Http2Channel extends EventEmitter implements Channel {
329329
stream: Http2CallStream,
330330
metadata: Metadata
331331
) {
332-
const connectMetadata: Promise<Metadata> = this.connect().then(
333-
() => metadata.clone()
332+
const connectMetadata: Promise<Metadata> = this.connect().then(() =>
333+
metadata.clone()
334334
);
335335
const finalMetadata: Promise<Metadata> = stream.filterStack.sendMetadata(
336336
connectMetadata

packages/grpc-js/src/server.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,6 @@ export class Server {
284284
this.http2Server.on(
285285
'stream',
286286
(stream: http2.ServerHttp2Stream, headers: http2.IncomingHttpHeaders) => {
287-
if (!this.started) {
288-
stream.end();
289-
return;
290-
}
291-
292287
const contentType = headers[http2.constants.HTTP2_HEADER_CONTENT_TYPE];
293288

294289
if (
@@ -351,6 +346,13 @@ export class Server {
351346
}
352347
}
353348
);
349+
350+
this.http2Server.on('session', session => {
351+
if (!this.started) {
352+
session.destroy();
353+
return;
354+
}
355+
});
354356
}
355357
}
356358

packages/grpc-js/src/stream-decoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class StreamDecoder {
3333
write(data: Buffer): Buffer[] {
3434
let readHead = 0;
3535
let toRead: number;
36-
let result: Buffer[] = [];
36+
const result: Buffer[] = [];
3737

3838
while (readHead < data.length) {
3939
switch (this.readState) {

0 commit comments

Comments
 (0)