FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: keep idle validation on native timers (#5397) · nodejs/undici@c9fbe9d · GitHub

/ undici Public

Commit c9fbe9d

Browse files
authored
fix: keep idle validation on native timers (#5397)
* fix: keep idle validation on native timers Signed-off-by: Matteo Collina <hello@matteocollina.com> * test: wait for poisoned idle socket disconnect Signed-off-by: Matteo Collina <hello@matteocollina.com> --------- Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 89323ff commit c9fbe9d

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎lib/dispatcher/client-h1.js‎

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

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

10281029
function clearIdleSocketValidation (socket) {
10291030
if (socket[kIdleSocketValidationTimeout]) {
1030-
clearTimeout(socket[kIdleSocketValidationTimeout])
1031+
clearTimeoutNative(socket[kIdleSocketValidationTimeout])
10311032
socket[kIdleSocketValidationTimeout] = null
10321033
}
10331034

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

10371038
function scheduleIdleSocketValidation (client, socket) {
10381039
socket[kIdleSocketValidation] = 1
1039-
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
1040+
socket[kIdleSocketValidationTimeout] = setTimeoutNative(() => {
10401041
socket[kIdleSocketValidationTimeout] = null
10411042
socket[kIdleSocketValidation] = 2
10421043

‎test/response-queue-poisoning.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const assert = require('node:assert')
4+
const { once } = require('node:events')
45
const { createServer } = require('node:http')
56
const { after, test } = require('node:test')
67
const { Client } = require('..')
@@ -37,6 +38,8 @@ test('should not reuse an idle socket with buffered unsolicited response bytes',
3738
const response1 = await client.request({ path: '/request1', method: 'GET' })
3839
assert.strictEqual(await readBody(response1.body), '/request1')
3940

41+
const disconnected = once(client, 'disconnect')
42+
4043
evilServerSocket.write(
4144
'HTTP/1.1 200 OK\r\n' +
4245
'Poison-Free-Socket: true\r\n' +
@@ -46,6 +49,8 @@ test('should not reuse an idle socket with buffered unsolicited response bytes',
4649
'\r\n'
4750
)
4851

52+
await disconnected
53+
4954
const response2 = await client.request({ path: '/request2', method: 'GET' })
5055
assert.strictEqual(response2.headers['poison-free-socket'], undefined)
5156
assert.strictEqual(await readBody(response2.body), '/request2')

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL