Skip to content

Commit 7ade907

Browse files
authored
feat(NODE-5190)!: remove deprecated keep alive options (#3771)
1 parent c407454 commit 7ade907

File tree

6 files changed

+1
-67
lines changed

6 files changed

+1
-67
lines changed

Diff for: src/cmap/connect.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,9 @@ const SOCKET_ERROR_EVENTS = new Set(SOCKET_ERROR_EVENT_LIST);
331331

332332
function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stream>) {
333333
const useTLS = options.tls ?? false;
334-
const keepAlive = options.keepAlive ?? true;
335-
const socketTimeoutMS = options.socketTimeoutMS ?? Reflect.get(options, 'socketTimeout') ?? 0;
336334
const noDelay = options.noDelay ?? true;
337335
const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
338336
const rejectUnauthorized = options.rejectUnauthorized ?? true;
339-
const keepAliveInitialDelay =
340-
((options.keepAliveInitialDelay ?? 120000) > socketTimeoutMS
341-
? Math.round(socketTimeoutMS / 2)
342-
: options.keepAliveInitialDelay) ?? 120000;
343337
const existingSocket = options.existingSocket;
344338

345339
let socket: Stream;
@@ -377,7 +371,7 @@ function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stre
377371
socket = net.createConnection(parseConnectOptions(options));
378372
}
379373

380-
socket.setKeepAlive(keepAlive, keepAliveInitialDelay);
374+
socket.setKeepAlive(true, 300000);
381375
socket.setTimeout(connectTimeoutMS);
382376
socket.setNoDelay(noDelay);
383377

Diff for: src/cmap/connection.ts

-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ export interface ConnectionOptions
122122
credentials?: MongoCredentials;
123123
connectTimeoutMS?: number;
124124
tls: boolean;
125-
/** @deprecated - Will not be able to turn off in the future. */
126-
keepAlive?: boolean;
127-
/** @deprecated - Will not be configurable in the future. */
128-
keepAliveInitialDelay?: number;
129125
noDelay?: boolean;
130126
socketTimeoutMS?: number;
131127
cancellationToken?: CancellationToken;

Diff for: src/connection_string.ts

-10
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,6 @@ export const OPTIONS = {
858858
return wc;
859859
}
860860
},
861-
keepAlive: {
862-
default: true,
863-
type: 'boolean',
864-
deprecated: 'Will not be able to turn off in the future.'
865-
},
866-
keepAliveInitialDelay: {
867-
default: 120000,
868-
type: 'uint',
869-
deprecated: 'Will not be configurable in the future.'
870-
},
871861
loadBalanced: {
872862
default: false,
873863
type: 'boolean'

Diff for: src/mongo_client.ts

-9
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,6 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
208208
writeConcern?: WriteConcern | WriteConcernSettings;
209209
/** TCP Connection no delay */
210210
noDelay?: boolean;
211-
/** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
212-
keepAlive?: boolean;
213-
/**
214-
* @deprecated The number of milliseconds to wait before initiating keepAlive on the TCP socket.
215-
* Will not be configurable in the future.
216-
*/
217-
keepAliveInitialDelay?: number;
218211
/** Force server to assign `_id` values instead of driver */
219212
forceServerObjectId?: boolean;
220213
/** A primary key factory function for generation of custom `_id` keys */
@@ -707,8 +700,6 @@ export interface MongoOptions
707700
| 'forceServerObjectId'
708701
| 'minHeartbeatFrequencyMS'
709702
| 'heartbeatFrequencyMS'
710-
| 'keepAlive'
711-
| 'keepAliveInitialDelay'
712703
| 'localThresholdMS'
713704
| 'maxConnecting'
714705
| 'maxIdleTimeMS'

Diff for: test/unit/connection_string.test.ts

-33
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
type MongoOptions,
1616
MongoParseError,
1717
MongoRuntimeError,
18-
OPTIONS,
1918
parseOptions,
2019
resolveSRVRecord
2120
} from '../mongodb';
@@ -726,36 +725,4 @@ describe('Connection String', function () {
726725
]);
727726
});
728727
});
729-
730-
context('default deprecated values', () => {
731-
afterEach(() => sinon.restore());
732-
before('ensure that `keepAlive` is deprecated', () => {
733-
const { deprecated } = OPTIONS.keepAlive;
734-
expect(deprecated).to.exist;
735-
});
736-
context('when no value is provided', () => {
737-
it('uses the default value', () => {
738-
const options = parseOptions('mongodb://localhost:27017');
739-
expect(options).to.have.property('keepAlive', true);
740-
});
741-
it('does not emit a deprecation warning', async () => {
742-
const spy = sinon.spy(process, 'emitWarning');
743-
parseOptions('mongodb://localhost:27017');
744-
expect(spy.called).to.be.false;
745-
});
746-
});
747-
748-
context('when a value is provided', () => {
749-
it('uses the provided value', () => {
750-
const options = parseOptions('mongodb://localhost:27017?keepAlive=false');
751-
expect(options).to.have.property('keepAlive', false);
752-
});
753-
it('emits a deprecation warning', async () => {
754-
const spy = sinon.spy(process, 'emitWarning');
755-
parseOptions('mongodb://localhost:27017?keepAlive=false');
756-
expect(spy.called, 'expected a warning to be emitted, but none was').to.be.true;
757-
expect(spy.getCalls()[0].args[0]).to.match(/keepAlive is a deprecated option/);
758-
});
759-
});
760-
});
761728
});

Diff for: test/unit/mongo_client.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ describe('MongoOptions', function () {
8787
ignoreUndefined: false,
8888
j: true,
8989
journal: false,
90-
keepAlive: true,
91-
keepAliveInitialDelay: 3,
9290
localThresholdMS: 3,
9391
maxConnecting: 5,
9492
maxIdleTimeMS: 3,
@@ -578,8 +576,6 @@ describe('MongoOptions', function () {
578576
['directconnection', false],
579577
['forceserverobjectid', false],
580578
['heartbeatfrequencyms', 10000],
581-
['keepalive', true],
582-
['keepaliveinitialdelay', 120000],
583579
['localthresholdms', 15],
584580
['maxidletimems', 0],
585581
['maxpoolsize', 100],

0 commit comments

Comments
 (0)