Skip to content

Commit

Permalink
feat(NODE-3607): update tcp keepalive options
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Apr 4, 2023
1 parent 30d2461 commit b3bcc7c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stre
const noDelay = options.noDelay ?? true;
const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
const rejectUnauthorized = options.rejectUnauthorized ?? true;
const keepAliveInitialDelay =
((options.keepAliveInitialDelay ?? 120000) > socketTimeoutMS
? Math.round(socketTimeoutMS / 2)
: options.keepAliveInitialDelay) ?? 120000;
// Default to delay to 300 seconds. Node automatically then sets TCP_KEEPINTVL to 1 second
// which is acceptable to the recommendation of 10 seconds and also cannot be configured.
// TCP_KEEPCNT is also set to 10 in Node and cannot be configured. (Recommendation is 9)
const keepAliveInitialDelay = options.keepAliveInitialDelay || 300000;
const existingSocket = options.existingSocket;

let socket: Stream;
Expand Down
2 changes: 2 additions & 0 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export interface ConnectionOptions
credentials?: MongoCredentials;
connectTimeoutMS?: number;
tls: boolean;
/** @deprecated - Will not be able to turn off in the future. */
keepAlive?: boolean;
/** @deprecated - Will not be configurable in the future. */
keepAliveInitialDelay?: number;
noDelay?: boolean;
socketTimeoutMS?: number;
Expand Down
4 changes: 3 additions & 1 deletion src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,14 @@ export const OPTIONS = {
return wc;
}
},
/** @deprecated - Will not be able to turn off in the future. */
keepAlive: {
default: true,
type: 'boolean'
},
/** @deprecated - Will not be configurable in the future. */
keepAliveInitialDelay: {
default: 120000,
default: 300000,
type: 'uint'
},
loadBalanced: {
Expand Down
7 changes: 5 additions & 2 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
sslCRL?: string;
/** TCP Connection no delay */
noDelay?: boolean;
/** TCP Connection keep alive enabled */
/** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
keepAlive?: boolean;
/** The number of milliseconds to wait before initiating keepAlive on the TCP socket */
/**
* @deprecated The number of milliseconds to wait before initiating keepAlive on the TCP socket.
* Will not be configurable in the future.
*/
keepAliveInitialDelay?: number;
/** Force server to assign `_id` values instead of driver */
forceServerObjectId?: boolean;
Expand Down

0 comments on commit b3bcc7c

Please sign in to comment.