{"record":{"id":"07caaa5837523574","repo":"dotnet/runtime","slug":"browserhttpwritestream-rejected-07caaa","errorCode":null,"errorMessage":"BrowserHttpWriteStream.Rejected","messagePattern":"BrowserHttpWriteStream\\.Rejected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/http.ts","lineNumber":110,"sourceCode":"    } catch (err) {\n        // ignore\n    }\n}\n\nexport function httpTransformStreamWrite(controller: HttpController, bufferPtr: VoidPtr, bufferLength: number): ControllablePromise<void> {\n    commonAsserts(controller);\n    dotnetAssert.check(bufferLength > 0, \"expected bufferLength > 0\");\n    // the bufferPtr is pinned by the caller\n    const view = new Span(bufferPtr, bufferLength, MemoryViewType.Byte);\n    const copy = view.slice() as Uint8Array;\n    return wrapAsCancelablePromise(async () => {\n        dotnetAssert.check(controller.streamWriter, \"expected streamWriter\");\n        dotnetAssert.check(controller.responsePromise, \"expected fetch promise\");\n        try {\n            await controller.streamWriter.ready;\n            await controller.streamWriter.write(copy);\n        } catch (ex) {\n            throw new Error(\"BrowserHttpWriteStream.Rejected\");\n        }\n    });\n}\n\nexport function httpTransformStreamClose(controller: HttpController): ControllablePromise<void> {\n    dotnetAssert.check(controller, \"expected controller\");\n    return wrapAsCancelablePromise(async () => {\n        dotnetAssert.check(controller.streamWriter, \"expected streamWriter\");\n        dotnetAssert.check(controller.responsePromise, \"expected fetch promise\");\n        try {\n            await controller.streamWriter.ready;\n            await controller.streamWriter.close();\n        } catch (ex) {\n            throw new Error(\"BrowserHttpWriteStream.Rejected\");\n        }\n    });\n}\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/dotnet/runtime/blob/b7130aa5e416e88ac48fafe92bf56a9d64e13c97/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/interop/http.ts#L92-L128","documentation":"Thrown by httpTransformStreamWrite() when the writable stream's ready/write promise rejected. This wraps the request-body upload path of a streaming HTTP request: controller.streamWriter.write(copy) failed, meaning the underlying fetch/stream was rejected by the network, server, or an abort. The original cause is intentionally swallowed and replaced with this generic message.","triggerScenarios":"Streaming a request body (httpFetchStream) and the connection failed: network error, server closed/reset, CORS rejection, TLS failure, or the request was aborted (httpAbort) mid-upload. The WritableStreamDefaultWriter rejected write/ready.","commonSituations":"Uploading large/streaming bodies over an unstable connection. CORS preflight rejected for the streaming POST. Server returned an error and closed the stream. Abort invoked during upload.","solutions":["Inspect the network tab / server logs for the real cause (CORS, status, reset) since the underlying error is masked here.","Ensure CORS allows the streaming request (method, headers, and that the browser supports duplex request streams — see httpSupportsStreamingRequest).","Handle the rejection in the C# streaming code and retry with a non-streaming upload if the environment doesn't support request streaming.","Make sure the request wasn't aborted (httpAbort) before/during the write."],"exampleFix":"// before - streaming upload over unsupported/CORS-blocked path\nawait httpFetchStream(controller, url, ...);\nawait httpTransformStreamWrite(controller, buf); // -> BrowserHttpWriteStream.Rejected\n\n// after - verify support, else fall back to buffered\nif (httpSupportsStreamingRequest()) {\n  await httpFetchStream(controller, url, ...);\n} else {\n  await httpFetchBytes(controller, url, ...); // buffered body\n}","handlingStrategy":"validation","validationCode":"// only stream request bodies where supported; else buffer\nif (httpSupportsStreamingRequest()) { httpFetchStream(controller, url, ...); } else { httpFetchBytes(controller, url, ...); }","typeGuard":"function streamingUploadSupported(): boolean { return httpSupportsStreamingRequest(); }","tryCatchPattern":"try { await httpTransformStreamWrite(controller, buf); } catch (e) { if (/BrowserHttpWriteStream.Rejected/.test(e.message)) { /* fall back to buffered upload; check CORS/network in devtools */ } else throw e; }","preventionTips":["Check httpSupportsStreamingRequest() before streaming uploads.","Verify CORS allows the streaming POST.","Avoid aborting mid-upload; handle aborts explicitly."],"tags":["http","streaming","fetch","upload","cors","wasm"],"analyzedSha":"b7130aa5e416e88ac48fafe92bf56a9d64e13c97","analyzedAt":"2026-08-07T06:17:13.108Z","schemaVersion":2},"datasetVersion":"2026-08-07T15:17:06.553Z"}