Skip to content

Commit

Permalink
fix: Send a close stream message when the stream input ends
Browse files Browse the repository at this point in the history
We currently don't send one of these messages when the `stream` input
ends, so the server can't know that the client is done!

This change now correctly sends the end-of-stream message.
  • Loading branch information
lhchavez committed Dec 13, 2023
1 parent 656c928 commit 3a37f39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions __tests__/invariants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,26 @@ describe('procedures should leave no trace after finishing', async () => {
const [input, output, close] = await client.test.echo.stream();
input.push({ msg: '1', ignore: false });
input.push({ msg: '2', ignore: false, end: true });
input.end();

const result1 = await iterNext(output);
assert(result1.ok);
expect(result1.payload).toStrictEqual({ response: '1' });

// ensure we only have one stream despite pushing multiple messages.
await new Promise((accept, _reject) => setTimeout(accept, 0));
expect(server.streams.size).toEqual(1);
input.end();
// ensure we no longer have any streams since the input was closed.
await new Promise((accept, _reject) => setTimeout(accept, 0));
expect(server.streams.size).toEqual(0);

const result2 = await iterNext(output);
assert(result2.ok);
expect(result2.payload).toStrictEqual({ response: '2' });

// ensure we exactly have one stream even after we send multiple messages
expect(server.streams.size).toEqual(1);

const result3 = await output.next();
assert(result3.done);

close();
// end procedure

Expand Down
2 changes: 2 additions & 0 deletions router/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ export const createClient = <Srv extends Server<Record<string, AnyService>>>(

transport.send(m);
}

transport.send(closeStream(transport.clientId, serverId, streamId));
})();

// transport -> output
Expand Down

0 comments on commit 3a37f39

Please sign in to comment.