Skip to content

Commit b3bcc7c

Browse files
committed
feat(NODE-3607): update tcp keepalive options
1 parent 30d2461 commit b3bcc7c

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/cmap/connect.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stre
333333
const noDelay = options.noDelay ?? true;
334334
const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
335335
const rejectUnauthorized = options.rejectUnauthorized ?? true;
336-
const keepAliveInitialDelay =
337-
((options.keepAliveInitialDelay ?? 120000) > socketTimeoutMS
338-
? Math.round(socketTimeoutMS / 2)
339-
: options.keepAliveInitialDelay) ?? 120000;
336+
// Default to delay to 300 seconds. Node automatically then sets TCP_KEEPINTVL to 1 second
337+
// which is acceptable to the recommendation of 10 seconds and also cannot be configured.
338+
// TCP_KEEPCNT is also set to 10 in Node and cannot be configured. (Recommendation is 9)
339+
const keepAliveInitialDelay = options.keepAliveInitialDelay || 300000;
340340
const existingSocket = options.existingSocket;
341341

342342
let socket: Stream;

src/cmap/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export interface ConnectionOptions
122122
credentials?: MongoCredentials;
123123
connectTimeoutMS?: number;
124124
tls: boolean;
125+
/** @deprecated - Will not be able to turn off in the future. */
125126
keepAlive?: boolean;
127+
/** @deprecated - Will not be configurable in the future. */
126128
keepAliveInitialDelay?: number;
127129
noDelay?: boolean;
128130
socketTimeoutMS?: number;

src/connection_string.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,12 +864,14 @@ export const OPTIONS = {
864864
return wc;
865865
}
866866
},
867+
/** @deprecated - Will not be able to turn off in the future. */
867868
keepAlive: {
868869
default: true,
869870
type: 'boolean'
870871
},
872+
/** @deprecated - Will not be configurable in the future. */
871873
keepAliveInitialDelay: {
872-
default: 120000,
874+
default: 300000,
873875
type: 'uint'
874876
},
875877
loadBalanced: {

src/mongo_client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
211211
sslCRL?: string;
212212
/** TCP Connection no delay */
213213
noDelay?: boolean;
214-
/** TCP Connection keep alive enabled */
214+
/** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
215215
keepAlive?: boolean;
216-
/** The number of milliseconds to wait before initiating keepAlive on the TCP socket */
216+
/**
217+
* @deprecated The number of milliseconds to wait before initiating keepAlive on the TCP socket.
218+
* Will not be configurable in the future.
219+
*/
217220
keepAliveInitialDelay?: number;
218221
/** Force server to assign `_id` values instead of driver */
219222
forceServerObjectId?: boolean;

0 commit comments

Comments
 (0)