fix(media): retire failed encoded senders from reusable slots
A relay flow can retain its physical slots while its input is absent. If an idle encoded writer fails, remove that sender from the slots themselves so input recovery cannot reuse a closed output. Preserve sibling senders and the current logical flow. A controlled production ChannelTransport/BrowserEncodingOutput test reproduces the idle failure and validates replacement without stopping another output or the shared source. Independent ownership review and the complete Session plus related encoder/OBS/diagnostic batch pass (970 tests).
This commit is contained in:
1 parent
e9956a5766
commit
28ff035f68
2 files changed
+33
-3
No files matched your search
@@ -630,7 +630,7 @@ export class ChannelTransport {
|
||||
const sender = binding.sender;
|
||||
const current = () => [...this.sending].find(([, output]) => output.senders.some(binding => binding.sender === sender));
|
||||
slot.encoded = new BrowserEncodingOutput(sender, () => {
|
||||
this.mediaSlots.delete(slots);
|
||||
slots.senders = slots.senders.filter(candidate => candidate.sender !== sender);
|
||||
const flow = current();
|
||||
if (flow) this.failOutput(flow[0], flow[1]);
|
||||
}, { get flowId() { return current()?.[0]; } });
|
||||
|
||||
@@ -8008,6 +8008,7 @@ const remoteStream = (id: string, tracks: MediaStreamTrack[]) => Object.assign(n
|
||||
function channelEncodingFixture() {
|
||||
vi.spyOn(encodingOutput, "supportsBrowserEncoding").mockReturnValue(true);
|
||||
const clones: MediaStreamTrack[] = [], carriers: MediaStreamTrack[] = [], claimed: RTCRtpSender[] = [];
|
||||
const pipes: ReadableStreamDefaultController<RTCEncodedVideoFrame>[] = [];
|
||||
let rejectClaim = false;
|
||||
const source = () => {
|
||||
const track = Object.assign(remoteTrack("video"), { enabled: true, contentHint: "detail",
|
||||
@@ -8028,7 +8029,7 @@ function channelEncodingFixture() {
|
||||
Object.assign(transceiver.sender, { createEncodedStreams: () => {
|
||||
claimed.push(transceiver.sender as unknown as RTCRtpSender);
|
||||
if (rejectClaim) { rejectClaim = false; throw new DOMException("sender claim refused", "InvalidStateError"); }
|
||||
return { readable: new ReadableStream<RTCEncodedVideoFrame>(), writable: new WritableStream<RTCEncodedVideoFrame>() };
|
||||
return { readable: new ReadableStream<RTCEncodedVideoFrame>({ start(controller) { pipes.push(controller); } }), writable: new WritableStream<RTCEncodedVideoFrame>() };
|
||||
} });
|
||||
return transceiver;
|
||||
});
|
||||
@@ -8046,7 +8047,7 @@ function channelEncodingFixture() {
|
||||
members.push(member);
|
||||
return member.handle;
|
||||
});
|
||||
return { source, clones, carriers, claimed, members, rejectNextClaim: () => { rejectClaim = true; } };
|
||||
return { source, clones, carriers, claimed, members, pipes, rejectNextClaim: () => { rejectClaim = true; } };
|
||||
}
|
||||
|
||||
test("room metrics read each PC once and follow current selected flows without mixing publications", async () => {
|
||||
@@ -9233,6 +9234,35 @@ test("pooled carriers retain the logical source and pending offer across replace
|
||||
for (const track of [...pool.clones, ...pool.carriers]) expect(track.stop).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("a relay flow reacquires a live encoded output after its idle sender pipe fails", async () => {
|
||||
RoomPeerConnection.instances = [];
|
||||
vi.stubGlobal("RTCPeerConnection", RoomPeerConnection);
|
||||
const pool = channelEncodingFixture(), videoPool = new BrowserEncodingPool(), source = pool.source();
|
||||
const failed = vi.fn(), outgoingFailed = vi.fn();
|
||||
const transport = new ChannelTransport({ polite: true, iceServers: [], videoPool, send() {},
|
||||
receive() {}, connected() {}, roomData() {}, failed, outgoingFailed });
|
||||
const screen = { kind: "screen" as const, stream: remoteStream("screen", [source]), profile: QUALITY_PROFILES["1080p30"] };
|
||||
const project = (available: boolean) => transport.setOutgoing(new Map([
|
||||
["relay", { ...screen, stream: available ? screen.stream : null }], ["sibling", screen],
|
||||
]));
|
||||
try {
|
||||
project(true);
|
||||
const [first, sibling] = pool.members;
|
||||
project(false);
|
||||
pool.pipes[0].error(new Error("idle encoder pipe failed"));
|
||||
await vi.waitFor(() => expect(first.encoded.track.stop).toHaveBeenCalled());
|
||||
project(true);
|
||||
await vi.waitFor(() => expect(pool.members).toHaveLength(3));
|
||||
const successor = pool.members[2];
|
||||
expect(successor.encoded).not.toBe(first.encoded);
|
||||
await expect(successor.configure()).resolves.toBe(true);
|
||||
expect(sibling.handle.dispose).not.toHaveBeenCalled();
|
||||
expect(source.stop).not.toHaveBeenCalled();
|
||||
expect(failed).not.toHaveBeenCalled();
|
||||
expect(outgoingFailed).not.toHaveBeenCalled();
|
||||
} finally { transport.close(); videoPool.dispose(); }
|
||||
});
|
||||
|
||||
test.each(["carrier", "source"])("retiring an in-flight %s releases its pending wait and preserves sibling senders", async operation => {
|
||||
RoomPeerConnection.instances = [];
|
||||
vi.stubGlobal("RTCPeerConnection", RoomPeerConnection);
|
||||
|
||||
Reference in new issue
Block a user