Visitar URL original
Reject NaN timeouts and cap huge ones instead of firing after 1 ms by imkrishn · Pull Request #54 · serpapi/serpapi-javascript · GitHub
Skip to content

Reject NaN timeouts and cap huge ones instead of firing after 1 ms - #54

Open
imkrishn wants to merge 1 commit into
serpapi:masterfrom
imkrishn:fix/timeout-values
Open

imkrishn wants to merge 1 commit into
serpapi:masterfrom
imkrishn:fix/timeout-values

Conversation

@imkrishn

@imkrishn imkrishn commented Oct 4, 2026

Copy link
Copy Markdown

validateTimeout() only checks timeout <= 0, which misses a couple of cases.

  • NaN gets through (NaN <= 0 is false), and then no timer is set at all. With a
    server that never replies, timeout: 2000 gave up after 2s but timeout: NaN
    was still waiting after 4s.

  • anything above 2147483647 ms makes Node's setTimeout fire after 1 ms. So
    timeout: Infinity fails almost immediately with RequestTimeoutError, even
    when the server answers fine.

I changed the check to !(timeout > 0) so NaN throws InvalidTimeoutError, and
capped the value at 2147483647 ( 2**32 -1 ). added tests for it in tests/validators_test.ts.

note that NaN used to be silently accepted and now throws. Capping instead of
rejecting big values was my call, so I can change that if you'd rather.

Before Fix

Screenshot from 2026-10-04 20-14-49

After Fix

Screenshot from 2026-10-04 20-15-36

You can see changes in above screenshots

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.

1 participant