diff --git a/shell/browser/net/node_stream_loader.cc b/shell/browser/net/node_stream_loader.cc index a2fa3a4c4e4f0..a5549155ff478 100644 --- a/shell/browser/net/node_stream_loader.cc +++ b/shell/browser/net/node_stream_loader.cc @@ -97,6 +97,9 @@ void NodeStreamLoader::ReadMore() { if (!ret.ToLocal(&buffer) || !node::Buffer::HasInstance(buffer)) { readable_ = false; is_reading_ = false; + if (ended_) { + NotifyComplete(result_); + } return; } diff --git a/spec-main/api-protocol-spec.ts b/spec-main/api-protocol-spec.ts index ddc2fd12271a9..62377a0132b6d 100644 --- a/spec-main/api-protocol-spec.ts +++ b/spec-main/api-protocol-spec.ts @@ -392,6 +392,25 @@ describe('protocol module', () => { const r = await ajax(protocolName + '://fake-host') expect(r.data).to.have.lengthOf(data.length) }) + + it('can handle a stream completing while writing', async () => { + function dumbPassthrough () { + return new stream.Transform({ + async transform (chunk, encoding, cb) { + cb(null, chunk) + } + }) + } + await registerStreamProtocol(protocolName, (request, callback) => { + callback({ + statusCode: 200, + headers: { 'Content-Type': 'text/plain' }, + data: getStream(1024 * 1024, Buffer.alloc(1024 * 1024 * 2)).pipe(dumbPassthrough()) + }) + }) + const r = await ajax(protocolName + '://fake-host') + expect(r.data).to.have.lengthOf(1024 * 1024 * 2) + }) }) describe('protocol.isProtocolHandled', () => {