Skip to content

Commit

Permalink
Fix a bug that caused HTTP2 sessions to be considered connected early
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Feb 19, 2025
1 parent 5f12dc2 commit bdd0dc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export class Http2SubchannelConnector implements SubchannelConnector {
let errorMessage = 'Failed to connect';
let reportedError = false;
session.unref();
session.once('connect', () => {
session.once('remoteSettings', () => {
session.removeAllListeners();
resolve(new Http2Transport(session, address, options, remoteName));
this.session = null;
Expand Down
19 changes: 17 additions & 2 deletions packages/grpc-js/test/test-channel-credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ describe('ChannelCredentials usage', () => {
done();
}
);

})
});
it('Should never connect when using insecure creds with a secure server', done => {
const client = new echoService(`localhost:${portNum}`, grpc.credentials.createInsecure());
const deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 1);
client.echo(
{ value: 'test value', value2: 3 },
new grpc.Metadata({waitForReady: true}),
{deadline},
(error: ServiceError, response: any) => {
client.close();
assert(error);
assert.strictEqual(error.code, grpc.status.DEADLINE_EXCEEDED);
done();
}
);
});
});

0 comments on commit bdd0dc8

Please sign in to comment.