restify / restify/clients

Request callback not called in node 14

Open
#232 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
58
Forks
35
Avg merge
22h 4m
Merged PRs (30d)
10

Description

restify-clients: 4.0.0
node: 14.15.0

The following code hangs without printing called in node v14.15.0. Works in v12.14.0

const http = require('http')
const restifyClients = require('restify-clients')
const sleep = require('util').promisify(setTimeout)

const server = http.createServer(async (req, res) => {
  res.writeHead(200)

  res.write('[')
  for (let i = 0; i < 10; i++) {
    if (res.socket.destroyed) return
    res.write(i + ',')
    await sleep(200)
  }
  res.end('10]')
})
server.requestTimeout = 1e3 

server.listen(8080, () => {
  const client = restifyClients.createJsonClient({
    url: 'http://localhost:8080',
    requestTimeout: 5000
  })
  client.get('/', (err, req, res, obj) => {
    console.log('called')
  })
})

From what I can tell, res emits "close" but not "end" so this code is never called.

Wireshark output:

$ tshark -i lo -f "host 127.0.0.1" -T fields -e frame.time_relative -e _ws.col.Protocol -e _ws.col.Info`
Capturing on 'Loopback: lo'
0.000000000     TCP     43652 → 8080 [SYN] Seq=0 Win=65495 Len=0 MSS=65495 SACK_PERM=1 TSval=3770375099 TSecr=0 WS=128
0.000013434     TCP     8080 → 43652 [SYN, ACK] Seq=0 Ack=1 Win=65483 Len=0 MSS=65495 SACK_PERM=1 TSval=3770375099 TSecr=3770375099 WS=128
0.000024256     TCP     43652 → 8080 [ACK] Seq=1 Ack=1 Win=65536 Len=0 TSval=3770375099 TSecr=3770375099
0.002999990     HTTP    GET / HTTP/1.1
0.003006304     TCP     8080 → 43652 [ACK] Seq=1 Ack=219 Win=65280 Len=0 TSval=3770375102 TSecr=3770375102
0.005889808     TCP     HTTP/1.1 200 OK  [TCP segment of a reassembled PDU]
0.005895692     TCP     43652 → 8080 [ACK] Seq=219 Ack=145 Win=65408 Len=0 TSval=3770375105 TSecr=3770375105
0.206851977     TCP     HTTP/1.1 200 OK  [TCP segment of a reassembled PDU]
0.206870358     TCP     43652 → 8080 [ACK] Seq=219 Ack=152 Win=65408 Len=0 TSval=3770375306 TSecr=3770375306
0.407125244     TCP     HTTP/1.1 200 OK  [TCP segment of a reassembled PDU]
0.407139384     TCP     43652 → 8080 [ACK] Seq=219 Ack=159 Win=65408 Len=0 TSval=3770375506 TSecr=3770375506
0.608472501     TCP     HTTP/1.1 200 OK  [TCP segment of a reassembled PDU]
0.608487828     TCP     43652 → 8080 [ACK] Seq=219 Ack=166 Win=65408 Len=0 TSval=3770375707 TSecr=3770375707
0.809010774     TCP     HTTP/1.1 200 OK  [TCP segment of a reassembled PDU]
0.809029832     TCP     43652 → 8080 [ACK] Seq=219 Ack=173 Win=65408 Len=0 TSval=3770375908 TSecr=3770375908
1.004352136     TCP     8080 → 43652 [FIN, ACK] Seq=173 Ack=219 Win=65536 Len=0 TSval=3770376103 TSecr=3770375908
1.006646880     TCP     43652 → 8080 [FIN, ACK] Seq=219 Ack=174 Win=65536 Len=0 TSval=3770376105 TSecr=3770376103
1.006667460     TCP     8080 → 43652 [ACK] Seq=174 Ack=220 Win=65536 Len=0 TSval=3770376105 TSecr=3770376105

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hanging request with Node v14.15.0 using the example in the issue, then inspect lib/HttpClient.js around line 317, where completion appears to depend on the response event. Compare the close and end events and verify that the request callback is invoked when the server closes the response after its timeout.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.