Skip to content

Commit fc2c539

Browse files
haorenfsaclaude
andauthored
feat: set grpc keepalive interval to 10s with 5s timeout (#501)
Reduce keepalive_time_ms from 55s to 10s to detect dead connections faster. Add tests for default keepalive options and user overrides. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9f5bca0 commit fc2c539

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

milvus/grpc/BaseClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class BaseClient {
126126
// So SDK should support max_receive_message_length unlimited.
127127
'grpc.max_receive_message_length': -1, // set max_receive_message_length to unlimited
128128
'grpc.max_send_message_length': -1, // set max_send_message_length to unlimited
129-
'grpc.keepalive_time_ms': 55 * 1000, // Send keepalive pings every 55 seconds, default is 2 hours.
129+
'grpc.keepalive_time_ms': 10 * 1000, // Send keepalive pings every 10 seconds, default is 2 hours.
130130
'grpc.keepalive_timeout_ms': 5 * 1000, // Keepalive ping timeout after 5 seconds, default is 20 seconds.
131131
'grpc.keepalive_permit_without_calls': 1, // Allow keepalive pings when there are no gRPC calls.
132132
'grpc.enable_retries': 1, // enable retry

test/grpc/MilvusClient.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,36 @@ describe(`Milvus client`, () => {
195195
}
196196
});
197197

198+
it(`should have default keepalive options set to 10s interval and 5s timeout`, async () => {
199+
const client = new MilvusClient({
200+
address: IP,
201+
__SKIP_CONNECT__: true,
202+
});
203+
204+
expect(client.channelOptions['grpc.keepalive_time_ms']).toEqual(10000);
205+
expect(client.channelOptions['grpc.keepalive_timeout_ms']).toEqual(5000);
206+
expect(client.channelOptions['grpc.keepalive_permit_without_calls']).toEqual(
207+
1
208+
);
209+
});
210+
211+
it(`should allow overriding keepalive options via channelOptions`, async () => {
212+
const client = new MilvusClient({
213+
address: IP,
214+
channelOptions: {
215+
'grpc.keepalive_time_ms': 20000,
216+
'grpc.keepalive_timeout_ms': 8000,
217+
},
218+
__SKIP_CONNECT__: true,
219+
});
220+
221+
expect(client.channelOptions['grpc.keepalive_time_ms']).toEqual(20000);
222+
expect(client.channelOptions['grpc.keepalive_timeout_ms']).toEqual(8000);
223+
expect(client.channelOptions['grpc.keepalive_permit_without_calls']).toEqual(
224+
1
225+
);
226+
});
227+
198228
it(`should add trace interceptor if enableTrace is true`, async () => {
199229
const nonTraceClient = new MilvusClient({
200230
address: IP,

0 commit comments

Comments
 (0)