Skip to content

Commit 4f11fd3

Browse files
tests
1 parent eab7b2f commit 4f11fd3

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/cmap/connection.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
237237
.on('error', this.onError.bind(this));
238238
this.socket.on('close', this.onClose.bind(this));
239239
this.socket.on('timeout', this.onTimeout.bind(this));
240+
241+
this.messageStream.pause();
240242
}
241243

242244
public get hello() {
@@ -427,11 +429,8 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
427429
): AsyncGenerator<MongoDBResponse> {
428430
this.throwIfAborted();
429431

430-
if (typeof options.socketTimeoutMS === 'number') {
431-
this.socket.setTimeout(options.socketTimeoutMS);
432-
} else if (this.socketTimeoutMS !== 0) {
433-
this.socket.setTimeout(this.socketTimeoutMS);
434-
}
432+
const socketTimeoutMS = options.socketTimeoutMS ?? this.socketTimeoutMS ?? 0;
433+
this.socket.setTimeout(socketTimeoutMS);
435434

436435
try {
437436
await this.writeCommand(message, {
@@ -455,11 +454,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
455454
yield document;
456455
this.throwIfAborted();
457456

458-
if (typeof options.socketTimeoutMS === 'number') {
459-
this.socket.setTimeout(options.socketTimeoutMS);
460-
} else if (this.socketTimeoutMS !== 0) {
461-
this.socket.setTimeout(this.socketTimeoutMS);
462-
}
457+
this.socket.setTimeout(socketTimeoutMS);
463458
}
464459
} finally {
465460
this.socket.setTimeout(0);

test/unit/cmap/connection.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Duplex } from 'node:stream';
1+
import { Socket } from 'node:net';
22

33
import { expect } from 'chai';
44
import * as sinon from 'sinon';
@@ -147,7 +147,7 @@ describe('new Connection()', function () {
147147
expect(error).to.have.property(beforeHandshakeSymbol, true);
148148
});
149149

150-
class MockSocket extends Duplex {
150+
class MockSocket extends Socket {
151151
override write(_data: string | Buffer) {
152152
return false;
153153
}
@@ -168,7 +168,7 @@ describe('new Connection()', function () {
168168
}
169169
}
170170

171-
describe('NODE-6370: regression test', function () {
171+
describe.only('NODE-6370: regression test', function () {
172172
let socket: MockSocket;
173173
let connection: Connection;
174174

@@ -314,7 +314,6 @@ describe('new Connection()', function () {
314314

315315
describe('when the data comes in multiple chunks', function () {
316316
it('does not hang', async function () {
317-
// MockSocket.DEBUG = true;
318317
const result$ = connection.command(
319318
MongoDBCollectionNamespace.fromString('foo.bar'),
320319
{ ping: 1 },

0 commit comments

Comments
 (0)