dotnet/runtime · error · Error

BrowserHttpWriteStream.Rejected

Error message

BrowserHttpWriteStream.Rejected

What it means

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.

Solutions

  1. Check the AbortController and the underlying network: a server-side reset or cancellation produces this error.
  2. 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.
  3. Wrap the managed HttpClient call in try/catch and surface the cancellation/network error to the user.

Example fix

// before: streaming POST fails on Safari
var content = new StreamContent(stream);
// after: guard streaming support
if (!RuntimeExports.http_wasm_supports_streaming_request())
    content = new ByteArrayContent(stream.ToArray());
Defensive patterns

Strategy: try-catch

Validate before calling

// before streaming a request body
if (!RuntimeExports.http_wasm_supports_streaming_request()) {
  content = new ByteArrayContent(await content.ReadAsByteArrayAsync());
}

Type guard

function supportsStreamingUpload(): boolean {
  return typeof Request !== 'undefined' && 'body' in Request.prototype
    && typeof ReadableStream === 'function'
    && typeof TransformStream === 'function';
}

Try / catch

try {
  await client.SendAsync(streamContent, token);
} catch (ex) {
  // BrowserHttpWriteStream.Rejected is the wrapped message
  if (token.IsCancellationRequested) throw new OperationCanceledException(ex);
  throw new HttpRequestException('streaming upload rejected by server/browser', ex);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/8ee707794faff2a7. Report an issue: GitHub.

Appendix: source

Thrown at src/mono/browser/runtime/http.ts:107

    } catch (err) {
        // ignore
    }
}

export function http_wasm_transform_stream_write (controller: HttpController, bufferPtr: VoidPtr, bufferLength: number): ControllablePromise<void> {
    if (BuildConfiguration === "Debug") commonAsserts(controller);
    mono_assert(bufferLength > 0, "expected bufferLength > 0");
    // the bufferPtr is pinned by the caller
    const view = new Span(bufferPtr, bufferLength, MemoryViewType.Byte);
    const copy = view.slice() as Uint8Array;
    return wrap_as_cancelable_promise(async () => {
        mono_assert(controller.streamWriter, "expected streamWriter");
        mono_assert(controller.responsePromise, "expected fetch promise");
        try {
            await controller.streamWriter.ready;
            await controller.streamWriter.write(copy);
        } catch (ex) {
            throw new Error("BrowserHttpWriteStream.Rejected");
        }
    });
}

export function http_wasm_transform_stream_close (controller: HttpController): ControllablePromise<void> {
    mono_assert(controller, "expected controller");
    return wrap_as_cancelable_promise(async () => {
        mono_assert(controller.streamWriter, "expected streamWriter");
        mono_assert(controller.responsePromise, "expected fetch promise");
        try {
            await controller.streamWriter.ready;
            await controller.streamWriter.close();
        } catch (ex) {
            throw new Error("BrowserHttpWriteStream.Rejected");
        }
    });
}

View on GitHub (pinned to 60108ba66e)