Skip to content

Commit 97c6330

Browse files
committed
Fix issue with recursive loop
1 parent 767d68b commit 97c6330

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

bin/start-e2e-test-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
npm run test:start-node-server &
44
npm run test:start-node-server2 &
55
./tests/e2e/grpc-go-server-reflection/grpc-reflection-server &
6-
sleep 2
6+
sleep 4

src/GrpcReflection.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,16 @@ export class GrpcReflection {
7575
*/
7676
getServiceMethods(descriptor: grpc.GrpcObject, service: string): Array<ListMethodsType>
7777
{
78-
let anti_recusive = 0
78+
let anti_recursive = 0
7979
let actualDescriptor : any = descriptor;
80-
let found = false;
8180
const path = this.generateServicePath(service);
8281
do {
83-
const service = path.pop();
84-
if (service && service in actualDescriptor){
85-
actualDescriptor = actualDescriptor[service];
86-
found = true;
82+
const serviceName = path.pop();
83+
if (serviceName && serviceName in actualDescriptor){
84+
actualDescriptor = actualDescriptor[serviceName];
8785
}
88-
anti_recusive++;
89-
}while(anti_recusive < 100 && !found);
86+
anti_recursive++
87+
} while (path.length > 0 && anti_recursive < 100);
9088
if ('service' in actualDescriptor) {
9189
return Object.entries(actualDescriptor.service)
9290
.map(([methodName, methodDefinition]) => ({

tests/e2e/listMethods.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {GrpcReflection} from "../../src";
1+
import {GrpcReflection, ReflectionRequestException} from "../../src";
22
import * as grpc from '@grpc/grpc-js';
33

44
describe("Test list methods of helloworld.proto", () => {
@@ -22,4 +22,8 @@ describe("Test list methods of helloworld.proto", () => {
2222

2323
});
2424

25+
it("Should thor exception on not found service", async() =>{
26+
await expect(client.listMethods('not-found.Greeter')).rejects.toThrow(ReflectionRequestException);
27+
});
28+
2529
});

0 commit comments

Comments
 (0)