Skip to content

Commit 78bcfe4

Browse files
authoredOct 4, 2022
fix(NODE-4608): prevent parallel monitor checks (#3404)
1 parent 1a550df commit 78bcfe4

File tree

2 files changed

+5
-43
lines changed

2 files changed

+5
-43
lines changed
 

‎src/sdam/monitor.ts

+4
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
328328

329329
function monitorServer(monitor: Monitor) {
330330
return (callback: Callback) => {
331+
if (monitor.s.state === STATE_MONITORING) {
332+
process.nextTick(callback);
333+
return;
334+
}
331335
stateTransition(monitor, STATE_MONITORING);
332336
function done() {
333337
if (!isInCloseState(monitor)) {
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,8 @@
1-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import { Socket } from 'net';
31
import * as path from 'path';
42

53
import { loadSpecTests } from '../../spec';
64
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
7-
import { TestFilter } from '../../tools/unified-spec-runner/schema';
8-
import { sleep } from '../../tools/utils';
9-
10-
const filter: TestFilter = ({ description }) => {
11-
switch (description) {
12-
case 'Network error on Monitor check':
13-
case 'Network timeout on Monitor check':
14-
return 'TODO(NODE-4608): Disallow parallel monitor checks';
15-
default:
16-
return false;
17-
}
18-
};
195

206
describe('SDAM Unified Tests', function () {
21-
afterEach(async function () {
22-
if (this.currentTest!.pending) {
23-
return;
24-
}
25-
// TODO(NODE-4573): fix socket leaks
26-
const LEAKY_TESTS = [
27-
'Command error on Monitor handshake',
28-
'Network error on Monitor check',
29-
'Network timeout on Monitor check',
30-
'Network error on Monitor handshake',
31-
'Network timeout on Monitor handshake'
32-
];
33-
34-
await sleep(250);
35-
const sockArray = (process as any)._getActiveHandles().filter(handle => {
36-
// Stdio are instanceof Socket so look for fd to be null
37-
return handle.fd == null && handle instanceof Socket && handle.destroyed !== true;
38-
});
39-
if (!sockArray.length) {
40-
return;
41-
}
42-
for (const sock of sockArray) {
43-
sock.destroy();
44-
}
45-
if (!LEAKY_TESTS.some(test => test === this.currentTest!.title)) {
46-
this.test!.error(new Error(`Test failed to clean up ${sockArray.length} socket(s)`));
47-
}
48-
});
49-
runUnifiedSuite(loadSpecTests(path.join('server-discovery-and-monitoring', 'unified')), filter);
7+
runUnifiedSuite(loadSpecTests(path.join('server-discovery-and-monitoring', 'unified')));
508
});

0 commit comments

Comments
 (0)
Please sign in to comment.