Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-5097): set timeout on write and reset on message #3590

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmap/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ function makeConnection(options: MakeConnectionOptions, _callback: Callback<Stre
}
}

socket.setTimeout(socketTimeoutMS);
socket.setTimeout(0);
callback(undefined, socket);
}

Expand Down
9 changes: 6 additions & 3 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
this[kDelayedTimeoutId] = null;
}

const socketTimeoutMS = this[kStream].timeout ?? 0;
this[kStream].setTimeout(0);

// always emit the message, in case we are streaming
this.emit('message', message);
let operationDescription = this[kQueue].get(message.responseTo);
Expand Down Expand Up @@ -410,8 +413,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
// back in the queue with the correct requestId and will resolve not being able
// to find the next one via the responseTo of the next streaming hello.
this[kQueue].set(message.requestId, operationDescription);
} else if (operationDescription.socketTimeoutOverride) {
this[kStream].setTimeout(this.socketTimeoutMS);
this[kStream].setTimeout(socketTimeoutMS);
}

try {
Expand Down Expand Up @@ -707,8 +709,9 @@ function write(
}

if (typeof options.socketTimeoutMS === 'number') {
operationDescription.socketTimeoutOverride = true;
conn[kStream].setTimeout(options.socketTimeoutMS);
} else if (conn.socketTimeoutMS !== 0) {
conn[kStream].setTimeout(conn.socketTimeoutMS);
}

// if command monitoring is enabled we need to modify the callback here
Expand Down
1 change: 0 additions & 1 deletion src/cmap/message_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface OperationDescription extends BSONSerializeOptions {
raw: boolean;
requestId: number;
session?: ClientSession;
socketTimeoutOverride?: boolean;
agreedCompressor?: CompressorName;
zlibCompressionLevel?: number;
$clusterTime?: Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { connect } from '../../../src/cmap/connect';
import { Connection } from '../../../src/cmap/connection';
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
import { Topology } from '../../../src/sdam/topology';
import { HostAddress, ns } from '../../../src/utils';
import { ns } from '../../../src/utils';
import { skipBrokenAuthTestBeforeEachHook } from '../../tools/runner/hooks/configuration';
import { assert as test, setupDatabase } from '../shared';

Expand Down Expand Up @@ -74,28 +74,6 @@ describe('Connection', function () {
}
});

it.skip('should support socket timeouts', {
// FIXME: NODE-2941
metadata: {
requires: {
os: '!win32' // 240.0.0.1 doesnt work for windows
}
},
test: function (done) {
const connectOptions = {
hostAddress: new HostAddress('240.0.0.1'),
connectionType: Connection,
connectionTimeout: 500
};

connect(connectOptions, err => {
expect(err).to.exist;
expect(err).to.match(/timed out/);
done();
});
}
});

it('should support calling back multiple times on exhaust commands', {
metadata: {
requires: { apiVersion: false, mongodb: '>=4.2.0', topology: ['single'] }
Expand Down
165 changes: 0 additions & 165 deletions test/unit/cmap/connect.test.js

This file was deleted.

Loading