Skip to content

Commit 1d38cc3

Browse files
committed
Merge remote-tracking branch 'upstream/@grpc/[email protected]' into v1.8.x_upmerge_3
2 parents e43fa71 + 15a3f1a commit 1d38cc3

File tree

3 files changed

+103
-24
lines changed

3 files changed

+103
-24
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.20",
3+
"version": "1.8.21",
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/server.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ import {
7373
unregisterChannelzRef,
7474
} from './channelz';
7575
import { CipherNameAndProtocol, TLSSocket } from 'tls';
76-
import { getErrorCode, getErrorMessage } from './error';
7776

7877
const UNLIMITED_CONNECTION_AGE_MS = ~(1 << 31);
7978
const KEEPALIVE_MAX_TIME_MS = ~(1 << 31);
@@ -846,11 +845,7 @@ export class Server {
846845
return true;
847846
}
848847

849-
private _retrieveHandler(
850-
headers: http2.IncomingHttpHeaders
851-
): Handler<any, any> {
852-
const path = headers[HTTP2_HEADER_PATH] as string;
853-
848+
private _retrieveHandler(path: string): Handler<any, any> | null {
854849
this.trace(
855850
'Received call to method ' +
856851
path +
@@ -866,7 +861,7 @@ export class Server {
866861
path +
867862
'. Sending UNIMPLEMENTED status.'
868863
);
869-
throw getUnimplementedStatusResponse(path);
864+
return null;
870865
}
871866

872867
return handler;
@@ -908,15 +903,12 @@ export class Server {
908903
return;
909904
}
910905

911-
let handler: Handler<any, any>;
912-
try {
913-
handler = this._retrieveHandler(headers);
914-
} catch (err) {
906+
const path = headers[HTTP2_HEADER_PATH] as string;
907+
908+
const handler = this._retrieveHandler(path);
909+
if (!handler) {
915910
this._respondWithError(
916-
{
917-
details: getErrorMessage(err),
918-
code: getErrorCode(err) ?? undefined,
919-
},
911+
getUnimplementedStatusResponse(path),
920912
stream,
921913
channelzSessionInfo
922914
);
@@ -970,15 +962,12 @@ export class Server {
970962
return;
971963
}
972964

973-
let handler: Handler<any, any>;
974-
try {
975-
handler = this._retrieveHandler(headers);
976-
} catch (err) {
965+
const path = headers[HTTP2_HEADER_PATH] as string;
966+
967+
const handler = this._retrieveHandler(path);
968+
if (!handler) {
977969
this._respondWithError(
978-
{
979-
details: getErrorMessage(err),
980-
code: getErrorCode(err) ?? undefined,
981-
},
970+
getUnimplementedStatusResponse(path),
982971
stream,
983972
null
984973
);

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ describe('Server', () => {
430430
(error: ServiceError, response: any) => {
431431
assert(error);
432432
assert.strictEqual(error.code, grpc.status.UNIMPLEMENTED);
433+
assert.match(error.details, /does not implement the method.*Div/);
433434
done();
434435
}
435436
);
@@ -439,6 +440,7 @@ describe('Server', () => {
439440
const call = client.sum((error: ServiceError, response: any) => {
440441
assert(error);
441442
assert.strictEqual(error.code, grpc.status.UNIMPLEMENTED);
443+
assert.match(error.details, /does not implement the method.*Sum/);
442444
done();
443445
});
444446

@@ -455,6 +457,7 @@ describe('Server', () => {
455457
call.on('error', (err: ServiceError) => {
456458
assert(err);
457459
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
460+
assert.match(err.details, /does not implement the method.*Fib/);
458461
done();
459462
});
460463
});
@@ -469,6 +472,93 @@ describe('Server', () => {
469472
call.on('error', (err: ServiceError) => {
470473
assert(err);
471474
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
475+
assert.match(err.details, /does not implement the method.*DivMany/);
476+
done();
477+
});
478+
479+
call.end();
480+
});
481+
});
482+
483+
describe('Unregistered service', () => {
484+
let server: Server;
485+
let client: ServiceClient;
486+
487+
const mathProtoFile = path.join(__dirname, 'fixtures', 'math.proto');
488+
const mathClient = (loadProtoFile(mathProtoFile).math as any).Math;
489+
490+
before(done => {
491+
server = new Server();
492+
// Don't register a service at all
493+
server.bindAsync(
494+
'localhost:0',
495+
ServerCredentials.createInsecure(),
496+
(err, port) => {
497+
assert.ifError(err);
498+
client = new mathClient(
499+
`localhost:${port}`,
500+
grpc.credentials.createInsecure()
501+
);
502+
server.start();
503+
done();
504+
}
505+
);
506+
});
507+
508+
after(done => {
509+
client.close();
510+
server.tryShutdown(done);
511+
});
512+
513+
it('should respond to a unary call with UNIMPLEMENTED', done => {
514+
client.div(
515+
{ divisor: 4, dividend: 3 },
516+
(error: ServiceError, response: any) => {
517+
assert(error);
518+
assert.strictEqual(error.code, grpc.status.UNIMPLEMENTED);
519+
assert.match(error.details, /does not implement the method.*Div/);
520+
done();
521+
}
522+
);
523+
});
524+
525+
it('should respond to a client stream with UNIMPLEMENTED', done => {
526+
const call = client.sum((error: ServiceError, response: any) => {
527+
assert(error);
528+
assert.strictEqual(error.code, grpc.status.UNIMPLEMENTED);
529+
assert.match(error.details, /does not implement the method.*Sum/);
530+
done();
531+
});
532+
533+
call.end();
534+
});
535+
536+
it('should respond to a server stream with UNIMPLEMENTED', done => {
537+
const call = client.fib({ limit: 5 });
538+
539+
call.on('data', (value: any) => {
540+
assert.fail('No messages expected');
541+
});
542+
543+
call.on('error', (err: ServiceError) => {
544+
assert(err);
545+
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
546+
assert.match(err.details, /does not implement the method.*Fib/);
547+
done();
548+
});
549+
});
550+
551+
it('should respond to a bidi call with UNIMPLEMENTED', done => {
552+
const call = client.divMany();
553+
554+
call.on('data', (value: any) => {
555+
assert.fail('No messages expected');
556+
});
557+
558+
call.on('error', (err: ServiceError) => {
559+
assert(err);
560+
assert.strictEqual(err.code, grpc.status.UNIMPLEMENTED);
561+
assert.match(err.details, /does not implement the method.*DivMany/);
472562
done();
473563
});
474564

0 commit comments

Comments
 (0)