dotnet/runtime · error · Error

BrowserHttpWriteStream.Rejected

Error message

BrowserHttpWriteStream.Rejected

What it means

Thrown by http_wasm_transform_stream_write when awaiting streamWriter.ready or streamWriter.write(copy) rejects. The original rejection is intentionally swallowed and replaced with this opaque message. It signals that a streaming HTTP request body write failed — most commonly because the underlying fetch/stream was aborted or the server rejected/closed the connection.

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 290d5ab72c)

Solutions

  1. Check whether the request was aborted via CancellationToken and treat abort as expected (catch and suppress).
  2. Verify the server accepts streaming request bodies and that the URL/method/headers are correct.
  3. Confirm the browser supports streaming requests (use http_wasm_supports_streaming_request to gate the feature); fall back to a buffered request if not.
  4. Inspect the muted debug log ('http muted: ...') for the underlying cause, since the thrown error is intentionally opaque.

Example fix

// before: write to a stream without handling rejection
// await http_wasm_transform_stream_write(controller, ptr, len); // throws opaque

// after: treat abort as expected, surface others
try {
  await http_wasm_transform_stream_write(controller, ptr, len);
} catch (e) {
  if (!controller.isAborted) throw e; // real failure
  // else: expected cancellation
}
Defensive patterns

Strategy: try-catch

Type guard

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

Try / catch

try {
  await controller.responsePromise; // or the streaming write API
} catch (e) {
  if (controller.isAborted) return; // expected
  throw e;
}

Prevention

When it happens

Trigger: Produced during a streaming PUT/POST when the WritableStreamDefaultWriter rejects: the request was aborted (http_wasm_abort), the network dropped, the server returned an error and closed the stream, or the browser does not support request streaming and the stream errored.

Common situations: See trigger scenarios.

Related errors


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