Skip to content

Commit

Permalink
fix: close() deadlock
Browse files Browse the repository at this point in the history
When no resume is going to be scheduled, request.onError might
never be detected.

Fixes: #344
  • Loading branch information
ronag committed Aug 19, 2020
1 parent 691feb2 commit 835d970
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/request-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const { test } = require('tap')
const { Client, errors } = require('..')
const { kConnect } = require('../lib/symbols')
const { createServer } = require('http')
const EventEmitter = require('events')
const FakeTimers = require('@sinonjs/fake-timers')
Expand Down Expand Up @@ -667,3 +668,32 @@ test('pipeline timeout', (t) => {
)
})
})

test('client.close should not deadlock', (t) => {
t.plan(2)

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))

const server = createServer((req, res) => {
})
t.teardown(server.close.bind(server))

server.listen(0, () => {
const client = new Client(`http:https://localhost:${server.address().port}`)
t.teardown(client.destroy.bind(client))

client[kConnect](() => {
client.request({ path: '/', method: 'GET', requestTimeout: 100 }, (err, response) => {
t.ok(err instanceof errors.RequestTimeoutError)
})

client.close((err) => {
console.error(new Error().stack)
t.error(err)
})

clock.tick(100)
})
})
})

0 comments on commit 835d970

Please sign in to comment.