You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request timeout does not cover stalled response bodies #206
The documented request timeout only lasts until fetch() resolves with response headers; it does not cover reading/parsing the response body.
fetchWithTimeout() clears its timer in src/core.ts:564-568 as soon as the fetch promise settles. defaultParseResponse() reads response.json()/response.text() later (src/core.ts:70-91) with no active timer. A server that sends headers and then stalls can therefore leave the SDK promise pending indefinitely, despite README.md stating that requests time out and throw APIConnectionTimeoutError.
Reproduction
importhttpfrom'node:http';importBrowserbasefrom'@browserbasehq/sdk';constserver=http.createServer((_req,res)=>{res.writeHead(200,{'content-type': 'application/json'});res.write('{');// send headers and a partial body, then stall});awaitnewPromise<void>((resolve)=>server.listen(0,'127.0.0.1',resolve));constaddress=server.address();if(!address||typeofaddress==='string')thrownewError('missing port');constclient=newBrowserbase({apiKey: 'test',baseURL: `http://127.0.0.1:${address.port}`,timeout: 50,maxRetries: 0,});constresult=awaitPromise.race([client.get('/stall').then(()=>'resolved',(error)=>error.constructor.name,),newPromise<string>((resolve)=>setTimeout(()=>resolve('still pending'),250)),]);console.log(result);// still pending, not APIConnectionTimeoutErrorserver.closeAllConnections();server.close();
Expected behavior
The request rejects with APIConnectionTimeoutError around 50 ms, including time spent receiving/parsing the body.
Actual behavior
The request remains pending after 250 ms and can hang indefinitely.
Why this matters
A partial or slow response defeats the SDK's primary bound on request duration. This can exhaust application concurrency and contradicts the timeout contract documented in README.md:135-154 and ClientOptions in src/index.ts:62-69.
Tested with Node 22.14.0 against @browserbasehq/sdk 2.18.0 / current main (b781bd7).
Activity