| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 04a17fe commit 484efd1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1408,7 +1408,13 @@ bool Stream::is_readable() const { | |||
| 1408 | 1408 | } | |
| 1409 | 1409 | ||
| 1410 | 1410 | BaseObjectPtr<Blob::Reader> Stream::get_reader() { | |
| 1411 | - if (!is_readable() || state()->has_reader) return {}; | ||
| 1411 | + if (state()->has_reader || !inbound_) return {}; | ||
| 1412 | + // Local unidirectional streams are never readable. | ||
| 1413 | + if (!is_pending() && direction() == Direction::UNIDIRECTIONAL && | ||
| 1414 | + ngtcp2_conn_is_local_stream(session(), id())) { | ||
| 1415 | + return {}; | ||
| 1416 | + } | ||
| 1417 | + | ||
| 1412 | 1418 | state()->has_reader = 1; | |
| 1413 | 1419 | auto reader = Blob::Reader::Create(env(), Blob::Create(env(), inbound_)); | |
| 1414 | 1420 | reader_ = reader; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,57 @@ | |||
| 1 | + // Flags: --experimental-quic --experimental-stream-iter --no-warnings | ||
| 2 | + | ||
| 3 | + // Test: reading a stream after its read side has received FIN, although | ||
| 4 | + // the stream is still alive. | ||
| 5 | + | ||
| 6 | + import { hasQuic, skip, mustCall } from '../common/index.mjs'; | ||
| 7 | + import { setTimeout as delay } from 'node:timers/promises'; | ||
| 8 | + import assert from 'node:assert'; | ||
| 9 | + | ||
| 10 | + const { deepStrictEqual } = assert; | ||
| 11 | + | ||
| 12 | + if (!hasQuic) { | ||
| 13 | + skip('QUIC is not enabled'); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + const { listen, connect } = await import('../common/quic.mjs'); | ||
| 17 | + const { bytes } = await import('stream/iter'); | ||
| 18 | + | ||
| 19 | + const expected = new TextEncoder().encode('data sent before any reader'); | ||
| 20 | + const serverSent = Promise.withResolvers(); | ||
| 21 | + const done = Promise.withResolvers(); | ||
| 22 | + | ||
| 23 | + const serverEndpoint = await listen(mustCall((serverSession) => { | ||
| 24 | + serverSession.onstream = mustCall(async (stream) => { | ||
| 25 | + // Reply with the full body plus FIN: | ||
| 26 | + stream.setBody(expected); | ||
| 27 | + serverSent.resolve(); | ||
| 28 | + await stream.closed; | ||
| 29 | + }); | ||
| 30 | + })); | ||
| 31 | + | ||
| 32 | + const clientSession = await connect(serverEndpoint.address); | ||
| 33 | + await clientSession.opened; | ||
| 34 | + | ||
| 35 | + const stream = await clientSession.createBidirectionalStream(); | ||
| 36 | + | ||
| 37 | + // Write a byte to open the stream: | ||
| 38 | + const writer = stream.writer; | ||
| 39 | + await writer.write(new Uint8Array([1])); | ||
| 40 | + | ||
| 41 | + // Wait until the server has sent its response, with a buffer for the local | ||
| 42 | + // delivery time itself. We can't actually read to check without undermining | ||
| 43 | + // the test itself unfortunately. | ||
| 44 | + await serverSent.promise; | ||
| 45 | + await delay(10); | ||
| 46 | + | ||
| 47 | + const received = await bytes(stream); | ||
| 48 | + deepStrictEqual(received, expected); | ||
| 49 | + | ||
| 50 | + writer.endSync(); | ||
| 51 | + await stream.closed; | ||
| 52 | + clientSession.close(); | ||
| 53 | + done.resolve(); | ||
| 54 | + | ||
| 55 | + await done.promise; | ||
| 56 | + await clientSession.closed; | ||
| 57 | + await serverEndpoint.close(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments