Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
45.5.0
What operating system(s) are you using?
Ubuntu
Operating System Version
Ubuntu 24.04.3 LTS (X11, Xvfb)
What arch are you using?
x64
Last Known Working Electron version
No response
Does the issue also appear in Chromium / Google Chrome?
I don't know how to test
Expected Behavior
A net.request POST with chunkedEncoding = true, sent on a reused keep-alive connection that the server closes without sending a response, fails with a network error. The network service keeps running.
Actual Behavior
The network service crashes (exit code 139, SIGSEGV) and restarts. The request fails with net::ERR_FAILED, and any other request in flight fails along with it:
Electron 45.5.0, Chromium 156.0.8078.109, chunked body
server: GET /first, request 1 on its connection, 0 B body
GET /first -> 200
server: POST /upload, request 2 on its connection, 100 B body
[2653424:1127/075033.980503:ERROR:content/browser/network_service_instance_impl.cc:652] Network service crashed or was terminated, restarting service.
POST /upload -> net::ERR_FAILED
child-process-gone {"type":"Utility","reason":"crashed","exitCode":139,"serviceName":"network.mojom.NetworkService","name":"Network Service"}
Testcase Gist URL
No response (the single-file test case is inline under Additional Information; it runs as is with electron main.js)
Additional Information
Steps: run electron main.js. The test server runs in the main process. It answers the first request on a connection, then reads the next POST on that connection in full and closes the socket without sending a response.
// electron main.js -> chunked body: the network service crashes
// electron main.js whole -> whole body: the server receives the POST twice
const { app, net } = require('electron');
const http = require('http');
// Keep-alive server: answers every request, except a POST that arrives on a
// reused connection, which it reads in full and then hangs up on (no response).
const served = new WeakMap();
const server = http.createServer((req, res) => {
const n = (served.get(req.socket) || 0) + 1;
served.set(req.socket, n);
let bytes = 0;
req.on('data', (c) => { bytes += c.length; });
req.on('end', () => {
console.log(`server: ${req.method} ${req.url}, request ${n} on its connection, ${bytes} B body`);
if (req.method === 'POST' && n > 1) return req.socket.destroy();
res.end('ok');
});
});
const chunked = !process.argv.includes('whole');
function send(method, url, body) {
return new Promise((resolve) => {
const req = net.request({ method, url });
req.on('response', (res) => { res.resume(); res.on('end', () => resolve(res.statusCode)); });
req.on('error', (e) => resolve(e.message));
if (body && chunked) {
req.chunkedEncoding = true;
req.write(body.subarray(0, 50));
req.write(body.subarray(50));
} else if (body) {
req.write(body);
}
req.end();
});
}
app.on('child-process-gone', (_e, d) => console.log('child-process-gone', JSON.stringify(d)));
app.whenReady().then(() => server.listen(0, '127.0.0.1', async () => {
const url = `http://127.0.0.1:${server.address().port}`;
console.log(`Electron ${process.versions.electron}, Chromium ${process.versions.chrome}, ${chunked ? 'chunked' : 'whole'} body`);
console.log('GET /first ->', await send('GET', `${url}/first`));
console.log('POST /upload ->', await send('POST', `${url}/upload`, Buffer.alloc(100, 'a')));
app.quit();
}));Versions: the crash reproduces every time on 45.2.1 (Chromium 156.0.8078.75), 45.5.0 (156.0.8078.109), 46.0.0-alpha.13 (160.0.8168.0) and 47.0.0-nightly.20261125 (160.0.8172.0). It also reproduces through a SOCKS5 proxy set with session.setProxy(). With a chunked body on a fresh connection there is no crash: the request fails with net::ERR_EMPTY_RESPONSE.
Whole body (electron main.js whole): no crash. Chromium sends the POST again on a new connection and the call succeeds, so the server receives the POST twice:
server: POST /upload, request 2 on its connection, 100 B body
server: POST /upload, request 1 on its connection, 100 B body
POST /upload -> 200
That is Chromium's resend of a request whose reused keep-alive connection closed before any response headers arrived, and may be by design. The crash with a chunked body is the bug reported here.
In-depth investigation
Backtrace of the crashing network service thread (Chrome_ChildIOThread) on 45.5.0, taken with gdb attached and symbolized with electron-v45.5.0-linux-x64-symbols.zip. The frames below #0 come from a stack scan. The fault address is 0x8, a read through a null pointer:
#0 network::mojom::ChunkedDataPipeGetterProxy::StartReading gen/services/network/public/mojom/chunked_data_pipe_getter.mojom.cc:226
#1 network::ChunkedDataPipeUploadDataStream::InitInternal services/network/chunked_data_pipe_upload_data_stream.cc:80
#2 net::UploadDataStream::Init net/base/upload_data_stream.cc:57
#3 net::HttpNetworkTransaction::DoLoop (DoInitRequestBody) net/http/http_network_transaction.cc:1514
#4 net::HttpNetworkTransaction::OnStreamReady net/http/http_network_transaction.cc:1041
#5 net::HttpStreamFactory::JobController::OnStreamReady
What appears to happen, reading the Chromium 156.0.8078.109 sources:
request.end()makes the getter report the body size.ChunkedDataPipeUploadDataStream::OnSizeReceived()gets it while a read is pending, the body is complete, and it callschunked_data_pipe_getter_.reset().- The server closes the reused connection without headers.
HttpNetworkTransaction::ShouldResendRequest()(connection reused, no headers received) restarts the transaction, which callsUploadDataStream::Init()again. InitInternal()guards withchunked_data_pipe_getter_.is_connected(). On an unboundmojo::Remote, that only DCHECKsis_bound(), then returns!encountered_error(), which istruewhen there is no endpoint client. The cache is disabled, so it callschunked_data_pipe_getter_->StartReading(...)through a null proxy.
net.request sets SetAllowHTTP1ForStreamingUpload(true) for chunked bodies (shell/common/api/electron_api_url_loader.cc). Chrome only allows fetch() streaming uploads over HTTP/2 or HTTP/3, which may be why the crash doesn't show up there. chunked_data_pipe_upload_data_stream.cc is unchanged on Chromium main. Checking is_bound() in InitInternal(), and returning net::ERR_FAILED when it is unbound, would avoid the crash.
Found while testing freedom-browser (solardev-xyz/freedom-browser#1344).
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fields👀 Unsorted Items
Activity
docs(0016, 0015): the device lane as built, L3's details, LDG-3's rel…
docs(0015): remote writes on guarded, proxy-verified write sessions; …