tomas / tomas/needle

Uncaught ECONNRESET exception

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

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
237
PR merge metrics
No merged PRs in 30d

Description

When I use Needle to check the following link the process fails with no error messages because of an uncaught exception. This makes it impossible to use in another system as it takes down the whole process.

I have found a solution but I do not understand the consequences of my change, nor do I know how to write tests for it. I hope someone else will be able to pick this up. Someone has obviously thought about this before and added some code but commented it out: https://github.com/tomas/needle/blob/f9d554e0ba1fc545fb406b6093b620bbab92c43c/lib/needle.js#L722-L727

My solution was to add the following in the same place:

    out.on('error', function(err) {
      had_error(err)
    });

Then when I run the test I get output: Error: aborted

Test:
DEBUG=needle node bin/needle get https://webharvest.gov/peth04/20041014212036/http://la.water.usgs.gov/pdfs/QW_DomWells_Chicot.pdf

  needle Making request #1 {
  agent: null,
  localAddress: undefined,
  lookup: undefined,
  protocol: 'https:',
  host: 'webharvest.gov',
  port: 443,
  path: '/peth04/20041014212036/http://la.water.usgs.gov/pdfs/QW_DomWells_Chicot.pdf',
  method: 'get',
  headers: {
    accept: '*/*',
    'user-agent': 'Needle/3.2.0 (Node.js v20.4.0; linux x64)',
    'accept-encoding': 'gzip, deflate, br',
    host: 'webharvest.gov'
  }
} +0ms
  needle Got response 302 {
  location: '/peth04/20041016222033/http://la.water.usgs.gov/pdfs/QW_DomWells_Chicot.pdf',
  'content-length': '0',
  date: 'Wed, 12 Jul 2023 08:21:15 GMT',
  server: 'Unknown',
  'strict-transport-security': 'max-age=63072000; includeSubDomains; preload'
} +538ms
  needle Redirecting to https://webharvest.gov/peth04/20041016222033/http://la.water.usgs.gov/pdfs/QW_DomWells_Chicot.pdf +1ms
  needle Making request #2 {
  agent: null,
  localAddress: undefined,
  lookup: undefined,
  protocol: 'https:',
  host: 'webharvest.gov',
  port: 443,
  path: '/peth04/20041016222033/http://la.water.usgs.gov/pdfs/QW_DomWells_Chicot.pdf',
  method: 'GET',
  headers: {
    accept: '*/*',
    'user-agent': 'Needle/3.2.0 (Node.js v20.4.0; linux x64)',
    'accept-encoding': 'gzip, deflate, br',
    host: 'webharvest.gov'
  }
} +0ms
  needle Got response 200 {
  'x-archive-orig-server': 'Microsoft-IIS/5.0',
  'x-archive-orig-etag': '"0baf7b02818c41:14c2"',
  'x-archive-orig-connection': 'close',
  'x-archive-orig-content-type': 'application/pdf',
  'x-archive-orig-last-modified': 'Thu, 01 Apr 2004 20:34:12 GMT',
  'x-archive-orig-content-length': '15081274',
  'x-archive-orig-date': 'Sat, 16 Oct 2004 22:20:48 GMT',
  'x-archive-orig-accept-ranges': 'bytes',
  'content-type': 'application/pdf',
  'content-length': '15081274',
  date: 'Wed, 12 Jul 2023 08:21:15 GMT',
  server: 'Unknown',
  'strict-transport-security': 'max-age=63072000; includeSubDomains; preload'
} +741ms
  needle Error: aborted
  needle     at connResetException (node:internal/errors:720:14)
  needle     at TLSSocket.socketCloseListener (node:_http_client:455:19)
  needle     at TLSSocket.emit (node:events:524:35)
  needle     at node:net:334:12
  needle     at TCP.done (node:_tls_wrap:631:7) +21s
  needle Error: aborted
  needle     at connResetException (node:internal/errors:720:14)
  needle     at TLSSocket.socketCloseListener (node:_http_client:455:19)
  needle     at TLSSocket.emit (node:events:524:35)
  needle     at node:net:334:12
  needle     at TCP.done (node:_tls_wrap:631:7) +0ms

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

Start in lib/needle.js around the commented error-handling code at lines 722-727, then reproduce the failure with the bin/needle command and the URL shown in the issue. Trace how the response stream handles ECONNRESET or aborted errors, and verify that the process no longer exits from an uncaught exception while the error is still reported to the caller.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.