There was an error while loading. Please reload this page.
1 parent 84b261d commit ef4bc84Copy full SHA for ef4bc84
2 files changed
crates/stdlib/src/ssl.rs
@@ -2344,7 +2344,7 @@ mod _ssl {
2344
// This prevents data loss when write_tls() drains rustls' internal buffer
2345
// but the socket cannot accept all the data immediately
2346
#[pytraverse(skip)]
2347
- pending_tls_output: PyMutex<Vec<u8>>,
+ pub(crate) pending_tls_output: PyMutex<Vec<u8>>,
2348
// Deferred client certificate verification error (for TLS 1.3)
2349
// Stores error message if client cert verification failed during handshake
2350
// Error is raised on first I/O operation after handshake
@@ -2762,7 +2762,9 @@ mod _ssl {
2762
if timed_out {
2763
// Keep unsent data in pending buffer
2764
*pending = pending[sent_total..].to_vec();
2765
- return Err(vm.new_os_error("Write operation timed out"));
+ return Err(
2766
+ timeout_error_msg(vm, "The write operation timed out".to_string()).upcast(),
2767
+ );
2768
}
2769
2770
let to_send = pending[sent_total..].to_vec();
@@ -2819,7 +2821,9 @@ mod _ssl {
2819
2821
self.pending_tls_output
2820
2822
.lock()
2823
.extend_from_slice(&buf[sent_total..]);
2824
2825
2826
2827
2828
2829
let to_send = buf[sent_total..].to_vec();
crates/stdlib/src/ssl/compat.rs
@@ -1026,15 +1026,29 @@ fn send_all_bytes(socket: &PySSLSocket, buf: Vec<u8>, vm: &VirtualMachine) -> Ss
1026
.try_into()
1027
.map_err(|_| SslError::Syscall("Invalid send return value".to_string()))?;
1028
if sent == 0 {
1029
- // No progress - would block
+ // No progress - save unsent bytes to pending buffer
1030
+ socket
1031
+ .pending_tls_output
1032
+ .lock()
1033
+ .extend_from_slice(&buf[sent_total..]);
1034
return Err(SslError::WantWrite);
1035
1036
sent_total += sent;
1037
1038
Err(e) => {
1039
if is_blocking_io_error(&e, vm) {
1040
+ // Save unsent bytes to pending buffer
1041
1042
1043
1044
1045
1046
1047
+ // For other errors, also save unsent bytes
1048
1049
1050
1051
1052
return Err(SslError::Py(e));
1053
1054
0 commit comments