Skip to content

Commit ac5394b

Browse files
committed
fix: keep idle validation on global timers
Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent b4c287b commit ac5394b

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

lib/dispatcher/client-h1.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* global WebAssembly */
44

55
const assert = require('node:assert')
6-
const { setTimeout: setTimeoutNative, clearTimeout: clearTimeoutNative } = require('node:timers')
76
const util = require('../core/util.js')
87
const { channels } = require('../core/diagnostics.js')
98
const timers = require('../util/timers.js')
@@ -1028,7 +1027,7 @@ function onSocketClose () {
10281027

10291028
function clearIdleSocketValidation (socket) {
10301029
if (socket[kIdleSocketValidationTimeout]) {
1031-
clearTimeoutNative(socket[kIdleSocketValidationTimeout])
1030+
clearTimeout(socket[kIdleSocketValidationTimeout])
10321031
socket[kIdleSocketValidationTimeout] = null
10331032
}
10341033

@@ -1037,7 +1036,7 @@ function clearIdleSocketValidation (socket) {
10371036

10381037
function scheduleIdleSocketValidation (client, socket) {
10391038
socket[kIdleSocketValidation] = 1
1040-
socket[kIdleSocketValidationTimeout] = setTimeoutNative(() => {
1039+
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
10411040
socket[kIdleSocketValidationTimeout] = null
10421041
socket[kIdleSocketValidation] = 2
10431042

test/interceptors/cache.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('Cache Interceptor', () => {
172172

173173
test('expires caching', async () => {
174174
const clock = FakeTimers.install({
175-
shouldClearNativeTimers: true
175+
toFake: ['Date']
176176
})
177177

178178
let requestsToOrigin = 0
@@ -249,7 +249,7 @@ describe('Cache Interceptor', () => {
249249

250250
test('expires caching with Etag', async () => {
251251
const clock = FakeTimers.install({
252-
shouldClearNativeTimers: true
252+
toFake: ['Date']
253253
})
254254

255255
let requestsToOrigin = 0
@@ -327,7 +327,7 @@ describe('Cache Interceptor', () => {
327327

328328
test('max-age caching', async () => {
329329
const clock = FakeTimers.install({
330-
shouldClearNativeTimers: true
330+
toFake: ['Date']
331331
})
332332

333333
let requestsToOrigin = 0
@@ -391,7 +391,7 @@ describe('Cache Interceptor', () => {
391391

392392
test('vary headers are present in revalidation request', async () => {
393393
const clock = FakeTimers.install({
394-
shouldClearNativeTimers: true
394+
toFake: ['Date']
395395
})
396396

397397
let requestsToOrigin = 0
@@ -670,7 +670,7 @@ describe('Cache Interceptor', () => {
670670

671671
test('stale-if-error (response)', async () => {
672672
const clock = FakeTimers.install({
673-
shouldClearNativeTimers: true
673+
toFake: ['Date']
674674
})
675675

676676
let requestsToOrigin = 0
@@ -752,7 +752,7 @@ describe('Cache Interceptor', () => {
752752
describe('Client-side directives', () => {
753753
test('max-age', async () => {
754754
const clock = FakeTimers.install({
755-
shouldClearNativeTimers: true
755+
toFake: ['Date']
756756
})
757757

758758
let requestsToOrigin = 0
@@ -813,7 +813,7 @@ describe('Cache Interceptor', () => {
813813

814814
test('max-stale', async () => {
815815
const clock = FakeTimers.install({
816-
shouldClearNativeTimers: true
816+
toFake: ['Date']
817817
})
818818

819819
let requestsToOrigin = 0
@@ -886,7 +886,7 @@ describe('Cache Interceptor', () => {
886886

887887
test('min-fresh', async () => {
888888
const clock = FakeTimers.install({
889-
shouldClearNativeTimers: true
889+
toFake: ['Date']
890890
})
891891

892892
let requestsToOrigin = 0
@@ -1104,7 +1104,7 @@ describe('Cache Interceptor', () => {
11041104

11051105
test('stale-if-error', async () => {
11061106
const clock = FakeTimers.install({
1107-
shouldClearNativeTimers: true
1107+
toFake: ['Date']
11081108
})
11091109

11101110
let requestsToOrigin = 0
@@ -1989,7 +1989,7 @@ describe('Cache Interceptor', () => {
19891989

19901990
describe('determineDeleteAt', () => {
19911991
test('max-age response has deleteAt proportional to freshness lifetime, not 1 year', async () => {
1992-
const clock = FakeTimers.install({ now: 1000 })
1992+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
19931993
after(() => clock.uninstall())
19941994

19951995
const store = new MemoryCacheStore()
@@ -2025,7 +2025,7 @@ describe('Cache Interceptor', () => {
20252025
})
20262026

20272027
test('sqlite store keeps short-lived entries past Date header precision loss so they can revalidate', { skip: runtimeFeatures.has('sqlite') === false }, async () => {
2028-
const clock = FakeTimers.install({ now: 1000, shouldClearNativeTimers: true })
2028+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
20292029
const store = new SqliteCacheStore()
20302030
let requestsToOrigin = 0
20312031
let revalidationHeaders
@@ -2101,7 +2101,7 @@ describe('Cache Interceptor', () => {
21012101
})
21022102

21032103
test('immutable response has deleteAt of ~1 year', async () => {
2104-
const clock = FakeTimers.install({ now: 1000 })
2104+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
21052105
after(() => clock.uninstall())
21062106

21072107
const store = new MemoryCacheStore()
@@ -2137,7 +2137,7 @@ describe('Cache Interceptor', () => {
21372137
})
21382138

21392139
test('stale-while-revalidate extends deleteAt beyond staleAt', async () => {
2140-
const clock = FakeTimers.install({ now: 1000 })
2140+
const clock = FakeTimers.install({ now: 1000, toFake: ['Date'] })
21412141
after(() => clock.uninstall())
21422142

21432143
const store = new MemoryCacheStore()

0 commit comments

Comments
 (0)