Linux: HTTPS request fails with SSL unexpected-eof when server closes without close_notify
Summary
On Linux, HTTPS requests fail with read failed: SSL_read failed: error:0A000126:SSL routines::unexpected eof while reading when the server closes the TCP connection without a TLS close_notify after already sending the complete HTTP response.
This is an OpenSSL 3 behavior change: a peer close without close_notify is now reported as SSL_R_UNEXPECTED_EOF_WHILE_READING, whereas OpenSSL 1.1.1 tolerated it as a plain EOF. Many CDNs/proxies in front of large APIs (we hit it with the Tencent EO / openresty layer in front of api.deepseek.com) close connections this way, so this affects a wide range of real-world endpoints.
Reproduction
A minimal HTTPS request in the same shape makepad sends (HTTP/1.1, Connection: close):
printf 'POST /chat/completions HTTP/1.1\r\nHost: api.deepseek.com\r\nConnection: close\r\nContent-Type: application/json\r\nAuthorization: Bearer invalid-test-key\r\nContent-Length: 89\r\n\r\n{"model":"deepseek-chat","messages":[{"role":"user","content":"ping"}],"max_tokens":4,"stream":false}' \
| openssl s_client -connect api.deepseek.com:443 -servername api.deepseek.com -quiet 2>&1 | tail -5Output: the full HTTP response is received (a 401 with a JSON body and Content-Length: 153), then the TLS layer reports:
4067EA29057F0000:error:0A000126:SSL routines::unexpected eof while reading:ssl/record/rec_layer_s3.c:698:
4067EA29057F0000:error:0A000197:SSL routines:SSL_shutdown:shutdown while in init:ssl/ssl_lib.c:2804:In makepad, the non-streaming path (platform/network/src/backend/linux/http.rs, read_response_head + the body-read loop) reads until connection close. Once the complete body has been read, the next SSL_read returns this error, and the whole request is reported as failed via handle_http_request_error — even though a valid HttpResponse was fully received. (The streaming path has the same issue at the "stream read failed" branch.)
Suggested fix
In OpenSslStream::read (platform/network/src/backend/linux/socket_stream.rs), treat SSL_ERROR_SSL with the queued OpenSSL error 0x0A000126 (SSL_R_UNEXPECTED_EOF_WHILE_READING) as Ok(0) (graceful EOF), matching what OpenSSL 1.1.1 did:
_ => {
// OpenSSL 3 surfaces a peer close without close_notify (common with
// CDNs) as SSL_R_UNEXPECTED_EOF_WHILE_READING (0x0A000126);
// treat it as a graceful EOF.
if unsafe { ERR_peek_error() } == 0x0A000126 {
Ok(0)
} else {
Err(io_other(format!("SSL_read failed: {}", last_ssl_error())))
}
}(Alternatively, stopping the read as soon as Content-Length bytes have been received would avoid the read entirely.)
Happy to turn this into a PR if the maintainers would like it.
Environment
- makepad
devbranch @fab5939d - Linux x86_64, system OpenSSL 3.x
Source: makepad/makepad