Skip to content

fix(utils): prevent unhandled error event and clean up timer on request timeout (fixes #34) - #52

Open
siddiqueirshad wants to merge 1 commit into
serpapi:masterfrom
siddiqueirshad:fix/issue-34-timeout-handling
Open

siddiqueirshad wants to merge 1 commit into
serpapi:masterfrom
siddiqueirshad:fix/issue-34-timeout-handling

Conversation

@siddiqueirshad

Copy link
Copy Markdown

Fixes #34

Cause

When a request timeout occurs, calling req.destroy() emits an error event on the ClientRequest instance. When the original error listener was detached via req.off("error", ...), Node.js raised an Unhandled 'error' event error, causing unhandled rejections or crashes.

Solution

  1. Clear timer references and attach a noop error handler prior to destroying the ClientRequest on timeout.
  2. Reject cleanly with RequestTimeoutError without emitting unhandled error events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout issues

1 participant