Skip to content

Commit 8be8197

Browse files
committed
wip
1 parent d45b2b4 commit 8be8197

File tree

6 files changed

+11
-47
lines changed

6 files changed

+11
-47
lines changed

.eslintrc.json

-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@
131131
{
132132
"selector": "CallExpression[callee.name='clearTimeout']",
133133
"message": "clearTimeout must remove abort listener"
134-
},
135-
{
136-
"selector": "CallExpression[callee.property.name='removeAllListeners'][arguments.length=0]",
137-
"message": "removeAllListeners can remove error listeners leading to uncaught errors"
138134
}
139135
],
140136
"@typescript-eslint/no-unused-vars": "error",

src/client-side-encryption/state_machine.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { type Abortable } from '../mongo_types';
1919
import { Timeout, type TimeoutContext, TimeoutError } from '../timeout';
2020
import {
2121
addAbortListener,
22-
addAbortSignalToStream,
2322
BufferPool,
2423
kDispose,
2524
MongoDBCollectionNamespace,
@@ -186,15 +185,10 @@ export type StateMachineOptions = {
186185
*/
187186
// TODO(DRIVERS-2671): clarify CSOT behavior for FLE APIs
188187
export class StateMachine {
189-
closeSignal: AbortSignal;
190-
191188
constructor(
192189
private options: StateMachineOptions,
193-
private bsonOptions = pluckBSONSerializeOptions(options),
194-
closeSignal: AbortSignal
195-
) {
196-
this.closeSignal = closeSignal;
197-
}
190+
private bsonOptions = pluckBSONSerializeOptions(options)
191+
) {}
198192

199193
/**
200194
* Executes the state machine according to the specification
@@ -456,7 +450,7 @@ export class StateMachine {
456450
await (options?.timeoutContext?.csotEnabled()
457451
? Promise.all([
458452
willResolveKmsRequest,
459-
Timeout.expires(options.timeoutContext.remainingTimeMS, this.closeSignal)
453+
Timeout.expires(options.timeoutContext?.remainingTimeMS)
460454
])
461455
: willResolveKmsRequest);
462456
} catch (error) {

src/cmap/connect.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
MongoRuntimeError,
1717
needsRetryableWriteLabel
1818
} from '../error';
19-
import { addAbortSignalToStream, HostAddress, ns, promiseWithResolvers } from '../utils';
19+
import { HostAddress, ns, promiseWithResolvers } from '../utils';
2020
import { AuthContext } from './auth/auth_provider';
2121
import { AuthMechanism } from './auth/providers';
2222
import {
@@ -387,8 +387,6 @@ export async function makeSocket(
387387
socket = net.createConnection(parseConnectOptions(options));
388388
}
389389

390-
addAbortSignalToStream(closeSignal, socket);
391-
392390
socket.unref();
393391
socket.setKeepAlive(true, 300000);
394392
socket.setTimeout(connectTimeoutMS);

src/mongo_client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
704704
// If maxPoolSize is 1 we won't be able to run anything
705705
// unless we interrupt whatever is using the one connection.
706706
this.closeController.abort(new MongoClientClosedError());
707+
this.closeController = new AbortController();
707708
}
708709

709710
const activeCursorCloses = Array.from(this.s.activeCursors, cursor => cursor.close());

src/utils.ts

-21
Original file line numberDiff line numberDiff line change
@@ -1555,24 +1555,3 @@ export async function abortable<T>(
15551555
abortListener?.[kDispose]();
15561556
}
15571557
}
1558-
1559-
export function addAbortSignalToStream(
1560-
signal: AbortSignal | undefined,
1561-
stream: Writable | Readable
1562-
) {
1563-
if (signal == null) {
1564-
return;
1565-
}
1566-
1567-
if (signal.aborted) {
1568-
stream.destroy(signal.reason);
1569-
return;
1570-
}
1571-
1572-
const abortListener = addAbortListener(signal, function () {
1573-
stream.off('close', abortListener[kDispose]).off('error', abortListener[kDispose]);
1574-
if (!stream.destroyed) stream.destroy(this.reason);
1575-
});
1576-
// not nearly as complex as node's eos() but... do we need all that?? sobbing emoji.
1577-
stream.once('close', abortListener[kDispose]).once('error', abortListener[kDispose]);
1578-
}

test/integration/sessions/sessions.test.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,15 @@ describe('Sessions Spec', function () {
7070
await test.setup(this.configuration);
7171
});
7272

73-
it('should send endSessions for multiple sessions', function (done) {
73+
it('should send endSessions for multiple sessions', async function () {
7474
const client = test.client;
7575
const sessions = [client.startSession(), client.startSession()].map(s => s.id);
7676

77-
client.close(err => {
78-
expect(err).to.not.exist;
79-
expect(test.commands.started).to.have.length(1);
80-
expect(test.commands.started[0].commandName).to.equal('endSessions');
81-
expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions);
82-
expect(client.s.activeSessions.size).to.equal(0);
83-
84-
done();
85-
});
77+
await client.close();
78+
expect(test.commands.started).to.have.lengthOf(1);
79+
expect(test.commands.started[0].commandName).to.equal('endSessions');
80+
expect(test.commands.started[0].command.endSessions).to.include.deep.members(sessions);
81+
expect(client.s.activeSessions.size).to.equal(0);
8682
});
8783
});
8884

0 commit comments

Comments
 (0)