Skip to content

[Bug]: negative setTimeout in timeoutRunner causing browserType.connect() crash #39166

@JJCella

Description

@JJCella

Version

v1.58.1 - latest

Steps to reproduce

Seems related to #35093

Call the browser.connect() function on a Node.js process that has been running for at least 24.8+ days (2147483647 ms) ; (we need to override performance.now for that)

Minimal repro here github.com/JJCella/playwright-minimal-repro

  1. npm i
  2. docker compose up -d
  3. tsx main.ts
import {chromium} from "playwright";
performance.now = () => 2147483647
const browser = await chromium.connect('ws://127.0.0.1:3001');
➜  new-project git:(main) tsx main.ts 
node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

browserType.connect: Timeout undefinedms exceeded

connect() is calling raceAgainstDeadline() with a deadline in browserType.ts

const deadline = params.timeout ? monotonicTime() + params.timeout : 0;

const result = await raceAgainstDeadline(async () => {

export function monotonicTime(): number {
return Math.floor((performance.now() + _timeShift) * 1000) / 1000;
}

After 2 147 483 647 millisecondes of nodeJS running, deadline reaches the max unsigned int32 and then timeout become negative

const kMaxDeadline = 2147483647; // 2^31-1
const timeout = (deadline || kMaxDeadline) - monotonicTime();
timer = setTimeout(() => resolve({ timedOut: true }), timeout);
}),

NodeJS is not happy about it and set the timeout duration to 1

(node:1) TimeoutNegativeWarning: -10510481.104000092 is a negative number.
Timeout duration was set to 1

Then the connect crashes with
browserType.connect: Timeout undefinedms exceeded

Expected behavior

Implementation should handle long running nodeJS processeses and not set negative timeouts

Actual behavior

connect() crashes with Timeout undefinedms exceeded error

browserType.connect: Timeout undefinedms exceeded
    at main (/Users/jeremy/new-project/main.ts:6:36)
    at <anonymous> (/Users/jeremy/new-project/main.ts:9:1)
    at Object.<anonymous> (/Users/jeremy/new-project/main.ts:9:6)
    at Object.transformer (/Users/jeremy/.nvm/versions/node/v24.10.0/lib/node_modules/tsx/dist/register-D46fvsV_.cjs:3:1104)

Additional context

No sure how to fix it but I would be happy to make a PR
Workaround possible : set a timeout to the connect() function (avoiding const timeout = kMaxDeadline - monotonicTime())
connect(uri, {timeout: 10000});

Environment

System:
    OS: Linux 5.15 Alpine Linux
    Container: Yes
  Binaries:
    Node: 24.10.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 11.6.1 - /usr/local/bin/npm
  npmPackages:
    playwright: 1.58.1 => 1.58.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions