clients icon indicating copy to clipboard operation
clients copied to clipboard

Request callback not called in node 14

Open luddd3 opened this issue 5 years ago • 0 comments

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

luddd3 avatar Nov 14 '20 17:11 luddd3