Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ReadableStream cannot be returned through a forwarded stub

Aperta
#228 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, typescript

Direzione di ricerca

Inizia con RpcPayload.ensureDeepCopied() e getHookForReadableStream, quindi riproduci l’esempio del broker a due sessioni riportato nell’issue. Verifica che un ReadableStream restituito tramite childStub.dup() raggiunga il chiamante senza l’errore owned-payload, mentre il comportamento della sessione diretta rimanga invariato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A ReadableStream returned by an RPC method works when the caller holds a direct session to the target. It throws when the call is forwarded through an intermediate session, such as when a broker returns a dup of a stub it holds to a third party.

  1. Create a session between a broker and a child. The child has a method that returns a ReadableStream.
  2. Create a second session between a caller and the broker. The broker exposes a method that returns childStub.dup().
  3. From the caller, resolve that stub and call the stream-returning method on it.

Expected: the caller receives a ReadableStream, the same as it would on a direct session.

Actual: Error: owned payload shouldn't contain raw ReadableStreams.

Cause: RpcPayload.ensureDeepCopied() sets source to "owned" after the first hop. getHookForReadableStream handles "params" and "return" and throws on anything else. Regular stubs forward across the same two sessions without error, so only streams hit this.

import { newMessagePortRpcSession, RpcTarget } from "capnweb";

class Child extends RpcTarget {
  async ping() { return "pong"; }
  async tail() {
    let i = 0;
    return new ReadableStream({
      pull(c) { if (i >= 3) return c.close(); c.enqueue(new Uint8Array([i++])); }
    });
  }
}

class Broker extends RpcTarget {
  constructor(child) { super(); this.child = child; }
  async resolveChild() { return this.child.dup(); }
}

const childChan = new MessageChannel();
newMessagePortRpcSession(childChan.port2, new Child());
const childFromBroker = newMessagePortRpcSession(childChan.port1);

const brokerChan = new MessageChannel();
newMessagePortRpcSession(brokerChan.port2, new Broker(childFromBroker));
const broker = newMessagePortRpcSession(brokerChan.port1);

const child = await broker.resolveChild();
console.log(await child.ping()); // "pong"
await child.tail();              // throws

Tested on capnweb 0.10.0. The same error string is present in 0.8.0.

Workaround: return an RpcTarget with a next() method instead of the stream, and rebuild the stream on the caller side.

Lingua principale
TypeScript
Stelle
4k
Fork
150
Merge medio
1g 19h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/capnweb

Tutte le issue di cloudflare/capnweb

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.