mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: correctly handle nexttick scheduling in stream reads (#24081)
Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
@@ -68,6 +68,8 @@ void NodeStreamLoader::Start(network::mojom::URLResponseHeadPtr head) {
|
||||
void NodeStreamLoader::NotifyReadable() {
|
||||
if (!readable_)
|
||||
ReadMore();
|
||||
else if (is_reading_)
|
||||
has_read_waiting_ = true;
|
||||
readable_ = true;
|
||||
}
|
||||
|
||||
@@ -101,8 +103,16 @@ void NodeStreamLoader::ReadMore() {
|
||||
// If there is no buffer read, wait until |readable| is emitted again.
|
||||
v8::Local<v8::Value> buffer;
|
||||
if (!ret.ToLocal(&buffer) || !node::Buffer::HasInstance(buffer)) {
|
||||
readable_ = false;
|
||||
is_reading_ = false;
|
||||
|
||||
// If 'readable' was called after 'read()', try again
|
||||
if (has_read_waiting_) {
|
||||
has_read_waiting_ = false;
|
||||
ReadMore();
|
||||
return;
|
||||
}
|
||||
|
||||
readable_ = false;
|
||||
if (ended_) {
|
||||
NotifyComplete(result_);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,11 @@ class NodeStreamLoader : public network::mojom::URLLoader {
|
||||
// flag.
|
||||
bool readable_ = false;
|
||||
|
||||
// It's possible for reads to be queued using nextTick() during read()
|
||||
// which will cause 'readable' to emit during ReadMore, so we track if
|
||||
// that occurred in a flag.
|
||||
bool has_read_waiting_ = false;
|
||||
|
||||
// Store the V8 callbacks to unsubscribe them later.
|
||||
std::map<std::string, v8::Global<v8::Value>> handlers_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user