{"record":{"id":"8ee707794faff2a7","repo":"dotnet/runtime","slug":"browserhttpwritestream-rejected","errorCode":null,"errorMessage":"BrowserHttpWriteStream.Rejected","messagePattern":"BrowserHttpWriteStream\\.Rejected","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/http.ts","lineNumber":107,"sourceCode":"    } catch (err) {\n        // ignore\n    }\n}\n\nexport function http_wasm_transform_stream_write (controller: HttpController, bufferPtr: VoidPtr, bufferLength: number): ControllablePromise<void> {\n    if (BuildConfiguration === \"Debug\") commonAsserts(controller);\n    mono_assert(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 wrap_as_cancelable_promise(async () => {\n        mono_assert(controller.streamWriter, \"expected streamWriter\");\n        mono_assert(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 http_wasm_transform_stream_close (controller: HttpController): ControllablePromise<void> {\n    mono_assert(controller, \"expected controller\");\n    return wrap_as_cancelable_promise(async () => {\n        mono_assert(controller.streamWriter, \"expected streamWriter\");\n        mono_assert(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":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/http.ts#L89-L125","documentation":"Thrown inside the cancelable promise returned by http_wasm_transform_stream_write in http.ts when awaiting streamWriter.ready or streamWriter.write(copy) rejects. The original rejection is swallowed and rethrown as a generic BrowserHttpWriteStream.Rejected so managed code sees a stable error. It signals the writable side of the TransformStream used for streaming HTTP request bodies has failed.","triggerScenarios":"Streaming an HTTP request body and the server closes/resets the connection mid-stream; the AbortController aborted the request while a write was in flight; the browser rejected the duplex stream (e.g. Safari without duplex support); network error during upload.","commonSituations":"Uploading large files with HttpClient.SendAsync over an unstable connection; calling HttpClient.Dispose / CancellationToken.Cancel during a streaming POST; a reverse proxy that rejects chunked transfer-encoding.","solutions":["Check the AbortController and the underlying network: a server-side reset or cancellation produces this error.","If the target browser does not support duplex streaming requests, fall back to a buffered request body (do not use HttpCompletionOption or set a stream content) or use http_wasm_supports_streaming_request to gate.","Wrap the managed HttpClient call in try/catch and surface the cancellation/network error to the user."],"exampleFix":"// before: streaming POST fails on Safari\nvar content = new StreamContent(stream);\n// after: guard streaming support\nif (!RuntimeExports.http_wasm_supports_streaming_request())\n    content = new ByteArrayContent(stream.ToArray());","handlingStrategy":"try-catch","validationCode":"// before streaming a request body\nif (!RuntimeExports.http_wasm_supports_streaming_request()) {\n  content = new ByteArrayContent(await content.ReadAsByteArrayAsync());\n}","typeGuard":"function supportsStreamingUpload(): boolean {\n  return typeof Request !== 'undefined' && 'body' in Request.prototype\n    && typeof ReadableStream === 'function'\n    && typeof TransformStream === 'function';\n}","tryCatchPattern":"try {\n  await client.SendAsync(streamContent, token);\n} catch (ex) {\n  // BrowserHttpWriteStream.Rejected is the wrapped message\n  if (token.IsCancellationRequested) throw new OperationCanceledException(ex);\n  throw new HttpRequestException('streaming upload rejected by server/browser', ex);\n}","preventionTips":["Check http_wasm_supports_streaming_request before using a stream body.","Do not abort the HttpClient mid-stream unless cancellation is expected.","Ensure the server accepts chunked/duplex uploads."],"tags":["http","streaming","upload","transform-stream","network"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}