Skip to content

Commit

Permalink
feat(NODE-5190)!: remove deprecated keep alive options (#3771)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Jul 13, 2023
1 parent c407454 commit 7ade907
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 67 deletions.
8 changes: 1 addition & 7 deletions src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,9 @@ const SOCKET_ERROR_EVENTS = new Set(SOCKET_ERROR_EVENT_LIST);

function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stream>) {
const useTLS = options.tls ?? false;
const keepAlive = options.keepAlive ?? true;
const socketTimeoutMS = options.socketTimeoutMS ?? Reflect.get(options, 'socketTimeout') ?? 0;
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;
const existingSocket = options.existingSocket;

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

socket.setKeepAlive(keepAlive, keepAliveInitialDelay);
socket.setKeepAlive(true, 300000);
socket.setTimeout(connectTimeoutMS);
socket.setNoDelay(noDelay);

Expand Down
4 changes: 0 additions & 4 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ 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;
cancellationToken?: CancellationToken;
Expand Down
10 changes: 0 additions & 10 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,16 +858,6 @@ export const OPTIONS = {
return wc;
}
},
keepAlive: {
default: true,
type: 'boolean',
deprecated: 'Will not be able to turn off in the future.'
},
keepAliveInitialDelay: {
default: 120000,
type: 'uint',
deprecated: 'Will not be configurable in the future.'
},
loadBalanced: {
default: false,
type: 'boolean'
Expand Down
9 changes: 0 additions & 9 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,6 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
writeConcern?: WriteConcern | WriteConcernSettings;
/** TCP Connection no delay */
noDelay?: boolean;
/** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
keepAlive?: boolean;
/**
* @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;
/** A primary key factory function for generation of custom `_id` keys */
Expand Down Expand Up @@ -707,8 +700,6 @@ export interface MongoOptions
| 'forceServerObjectId'
| 'minHeartbeatFrequencyMS'
| 'heartbeatFrequencyMS'
| 'keepAlive'
| 'keepAliveInitialDelay'
| 'localThresholdMS'
| 'maxConnecting'
| 'maxIdleTimeMS'
Expand Down
33 changes: 0 additions & 33 deletions test/unit/connection_string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
type MongoOptions,
MongoParseError,
MongoRuntimeError,
OPTIONS,
parseOptions,
resolveSRVRecord
} from '../mongodb';
Expand Down Expand Up @@ -726,36 +725,4 @@ describe('Connection String', function () {
]);
});
});

context('default deprecated values', () => {
afterEach(() => sinon.restore());
before('ensure that `keepAlive` is deprecated', () => {
const { deprecated } = OPTIONS.keepAlive;
expect(deprecated).to.exist;
});
context('when no value is provided', () => {
it('uses the default value', () => {
const options = parseOptions('mongodb://localhost:27017');
expect(options).to.have.property('keepAlive', true);
});
it('does not emit a deprecation warning', async () => {
const spy = sinon.spy(process, 'emitWarning');
parseOptions('mongodb://localhost:27017');
expect(spy.called).to.be.false;
});
});

context('when a value is provided', () => {
it('uses the provided value', () => {
const options = parseOptions('mongodb://localhost:27017?keepAlive=false');
expect(options).to.have.property('keepAlive', false);
});
it('emits a deprecation warning', async () => {
const spy = sinon.spy(process, 'emitWarning');
parseOptions('mongodb://localhost:27017?keepAlive=false');
expect(spy.called, 'expected a warning to be emitted, but none was').to.be.true;
expect(spy.getCalls()[0].args[0]).to.match(/keepAlive is a deprecated option/);
});
});
});
});
4 changes: 0 additions & 4 deletions test/unit/mongo_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ describe('MongoOptions', function () {
ignoreUndefined: false,
j: true,
journal: false,
keepAlive: true,
keepAliveInitialDelay: 3,
localThresholdMS: 3,
maxConnecting: 5,
maxIdleTimeMS: 3,
Expand Down Expand Up @@ -578,8 +576,6 @@ describe('MongoOptions', function () {
['directconnection', false],
['forceserverobjectid', false],
['heartbeatfrequencyms', 10000],
['keepalive', true],
['keepaliveinitialdelay', 120000],
['localthresholdms', 15],
['maxidletimems', 0],
['maxpoolsize', 100],
Expand Down

0 comments on commit 7ade907

Please sign in to comment.