-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: add diagnostics_channel event for completion #42822
base: main
Are you sure you want to change the base?
Conversation
let streamDoneChannel; | ||
function getStreamDoneChannel () { | ||
return streamDoneChannel ||= dc.channel('stream.web.done'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this lazy-loading, I had tried to just create the channel immediately. However, this resulted in the following error at build time:
$ make -j24
ninja -C out/Release
ninja: Entering directory `out/Release'
[21/25] ACTION node: node_mksnapshot_9b7a2d2290b02e76d66661df74749f56
FAILED: gen/node_snapshot.cc
cd ../../; out/Release/node_mksnapshot out/Release/gen/node_snapshot.cc
global handle not serialized: 0x2c1d47302cd9: [JS_API_OBJECT_TYPE] in OldSpace
- map: 0x08188aa5fd61 <Map(HOLEY_ELEMENTS)> [FastProperties]
- prototype: 0x12df1ab07b79 <Object map = 0x8188aa5fd19>
- elements: 0x20e18df01329 <FixedArray[0]> [HOLEY_ELEMENTS]
- embedder fields: 1
- properties: 0x20e18df01329 <FixedArray[0]>
- All own properties (excluding elements): {}
- embedder fields = {
21965, aligned pointer: 0x55cde06a73c0
}
global handle not serialized: 0x2c1d47302b49: [JS_OBJECT_TYPE] in OldSpace
- map: 0x0f4b222452b9 <Map(HOLEY_ELEMENTS)> [FastProperties]
- prototype: 0x2c1d473027a9 <Channel map = 0xf4b22245229>
- elements: 0x20e18df01329 <FixedArray[0]> [HOLEY_ELEMENTS]
- properties: 0x20e18df01329 <FixedArray[0]>
- All own properties (excluding elements): {
0x218677ef8c49: [String] in OldSpace: #_subscribers: 0x20e18df015b9 <undefined> (const data field 0), location: in-object
0x20e18df058f1: [String] in ReadOnlySpace: #name: 0x218677ede9d1 <String[15]: #stream.web.done> (const data field 1), location: in-object
}
#
# Fatal error in , line 0
# Check failed: handle_checker.CheckGlobalAndEternalHandles().
#
#
#
#FailureMessage Object: 0x7ffefc883920
1: 0x55cddae43c35 [out/Release/node_mksnapshot]
2: 0x55cddbcc2926 V8_Fatal(char const*, ...) [out/Release/node_mksnapshot]
3: 0x55cddb396b05 v8::SnapshotCreator::CreateBlob(v8::SnapshotCreator::FunctionCodeHandling) [out/Release/node_mksnapshot]
4: 0x55cddae6f680 node::SnapshotBuilder::Generate(node::SnapshotData*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >) [out/Release/node_mksnapshot]
5: 0x55cddae707f4 node::SnapshotBuilder::Generate(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >) [out/Release/node_mksnapshot]
6: 0x55cddad822f2 BuildSnapshot(int, char**) [out/Release/node_mksnapshot]
7: 0x7f4802c9dfd0 [/lib/x86_64-linux-gnu/libc.so.6]
8: 0x7f4802c9e07d __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
9: 0x55cdda8c9e05 _start [out/Release/node_mksnapshot]
Trace/breakpoint trap (core dumped)
ninja: build stopped: subcommand failed.
make: *** [Makefile:127: node] Error 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @joyeecheung
So long as there are no observable differences to the actual streams API, this is great. I would be concerned about possible performance impact but this code already has performance issues and this is not likely to be the primary bottleneck. |
This adds a
stream.web.done
diagnostics channel to Web Streams. with the intention of having a straightforward way to detect when aReadableStream
has been read to completion, without triggering the reading of the stream.This is useful for instrumentation tools trying to measure the length of a request/response cycle triggered by a
fetch()
.Why draft?
Right now I'm only testing directly calling
read()
and async iterators.pipeThrough()
,pipeTo()
, and cancellation all need to be tested (and perhaps implemented).Also, the naming is certainly open for suggestions. I based the name of the channel on the only other prior art in Node.js core.
Finally, I had a weird thing happen with
mksnapshot
, so I'm wondering if anyone knows how to better work around that. See the inline comment below.All that being said, I thought it was worth opening it now anyway, to make sure the approach is sound and agreeable.