From c5cfe214ac320386033effc1b62967efa0eabf46 Mon Sep 17 00:00:00 2001 From: Alec Gibson <12036746+alecgibson@users.noreply.github.com> Date: Tue, 19 Jul 2022 18:56:43 +0100 Subject: [PATCH] fix(NODE-4444): use Node.js clear timers (#3327) --- .eslintrc.json | 12 ++++++++++++ src/cmap/connection.ts | 2 +- src/cmap/connection_pool.ts | 2 +- src/sdam/common.ts | 2 ++ src/sdam/monitor.ts | 2 +- src/sdam/srv_polling.ts | 2 +- src/sdam/topology.ts | 2 +- src/utils.ts | 2 +- test/integration/objectid.test.js | 2 +- test/unit/sdam/topology.test.js | 2 +- 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 354cd1b669..fe97f49671 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -41,6 +41,18 @@ ], "no-restricted-globals": [ "error", + { + "name": "clearTimeout", + "message": "Use `import { clearTimeout } from 'timers';` instead" + }, + { + "name": "clearImmediate", + "message": "Use `import { clearImmediate } from 'timers';` instead" + }, + { + "name": "clearInterval", + "message": "Use `import { clearInterval } from 'timers';` instead" + }, { "name": "setTimeout", "message": "Use `import { setTimeout } from 'timers';` instead" diff --git a/src/cmap/connection.ts b/src/cmap/connection.ts index 97502d63d0..508a5c3c0f 100644 --- a/src/cmap/connection.ts +++ b/src/cmap/connection.ts @@ -1,4 +1,4 @@ -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import type { BSONSerializeOptions, Document, ObjectId } from '../bson'; import { diff --git a/src/cmap/connection_pool.ts b/src/cmap/connection_pool.ts index 9adae0a3f5..9a13b7d486 100644 --- a/src/cmap/connection_pool.ts +++ b/src/cmap/connection_pool.ts @@ -1,5 +1,5 @@ import Denque = require('denque'); -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import type { ObjectId } from '../bson'; import { diff --git a/src/sdam/common.ts b/src/sdam/common.ts index 6738ad9eb8..a2ffd89491 100644 --- a/src/sdam/common.ts +++ b/src/sdam/common.ts @@ -1,3 +1,5 @@ +import { clearTimeout } from 'timers'; + import type { Binary, Long, Timestamp } from '../bson'; import type { ClientSession } from '../sessions'; import type { Topology } from './topology'; diff --git a/src/sdam/monitor.ts b/src/sdam/monitor.ts index cd1bc092f4..51e92b358e 100644 --- a/src/sdam/monitor.ts +++ b/src/sdam/monitor.ts @@ -1,4 +1,4 @@ -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import { Document, Long } from '../bson'; import { connect } from '../cmap/connect'; diff --git a/src/sdam/srv_polling.ts b/src/sdam/srv_polling.ts index 71ee20a477..b61284a5e8 100644 --- a/src/sdam/srv_polling.ts +++ b/src/sdam/srv_polling.ts @@ -1,5 +1,5 @@ import * as dns from 'dns'; -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import { MongoRuntimeError } from '../error'; import { Logger, LoggerOptions } from '../logger'; diff --git a/src/sdam/topology.ts b/src/sdam/topology.ts index a3505bd7a9..789db325af 100644 --- a/src/sdam/topology.ts +++ b/src/sdam/topology.ts @@ -1,5 +1,5 @@ import Denque = require('denque'); -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import { promisify } from 'util'; import type { BSONSerializeOptions, Document } from '../bson'; diff --git a/src/utils.ts b/src/utils.ts index a041e7fdf8..f7f0ebd545 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,7 +1,7 @@ import * as crypto from 'crypto'; import type { SrvRecord } from 'dns'; import * as os from 'os'; -import { setTimeout } from 'timers'; +import { clearTimeout, setTimeout } from 'timers'; import { URL } from 'url'; import { Document, ObjectId, resolveBSONOptions } from './bson'; diff --git a/test/integration/objectid.test.js b/test/integration/objectid.test.js index 7d19818fa9..19ae635048 100644 --- a/test/integration/objectid.test.js +++ b/test/integration/objectid.test.js @@ -3,7 +3,7 @@ var test = require('./shared').assert; const { expect } = require('chai'); var setupDatabase = require('./shared').setupDatabase; const { ObjectId } = require('../../src'); -const { setInterval } = require('timers'); +const { clearInterval, setInterval } = require('timers'); const { sleep } = require('../tools/utils'); describe('ObjectId', function () { diff --git a/test/unit/sdam/topology.test.js b/test/unit/sdam/topology.test.js index d4f0617504..978386697b 100644 --- a/test/unit/sdam/topology.test.js +++ b/test/unit/sdam/topology.test.js @@ -1,6 +1,6 @@ 'use strict'; -const { setTimeout } = require('timers'); +const { clearTimeout, setTimeout } = require('timers'); const mock = require('../../tools/mongodb-mock/index'); const { expect } = require('chai'); const sinon = require('sinon');