Skip to content

Commit ef4bc84

Browse files
committed
pending handling more
1 parent 84b261d commit ef4bc84

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

crates/stdlib/src/ssl.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ mod _ssl {
23442344
// This prevents data loss when write_tls() drains rustls' internal buffer
23452345
// but the socket cannot accept all the data immediately
23462346
#[pytraverse(skip)]
2347-
pending_tls_output: PyMutex<Vec<u8>>,
2347+
pub(crate) pending_tls_output: PyMutex<Vec<u8>>,
23482348
// Deferred client certificate verification error (for TLS 1.3)
23492349
// Stores error message if client cert verification failed during handshake
23502350
// Error is raised on first I/O operation after handshake
@@ -2762,7 +2762,9 @@ mod _ssl {
27622762
if timed_out {
27632763
// Keep unsent data in pending buffer
27642764
*pending = pending[sent_total..].to_vec();
2765-
return Err(vm.new_os_error("Write operation timed out"));
2765+
return Err(
2766+
timeout_error_msg(vm, "The write operation timed out".to_string()).upcast(),
2767+
);
27662768
}
27672769

27682770
let to_send = pending[sent_total..].to_vec();
@@ -2819,7 +2821,9 @@ mod _ssl {
28192821
self.pending_tls_output
28202822
.lock()
28212823
.extend_from_slice(&buf[sent_total..]);
2822-
return Err(vm.new_os_error("Write operation timed out"));
2824+
return Err(
2825+
timeout_error_msg(vm, "The write operation timed out".to_string()).upcast(),
2826+
);
28232827
}
28242828

28252829
let to_send = buf[sent_total..].to_vec();

crates/stdlib/src/ssl/compat.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,15 +1026,29 @@ fn send_all_bytes(socket: &PySSLSocket, buf: Vec<u8>, vm: &VirtualMachine) -> Ss
10261026
.try_into()
10271027
.map_err(|_| SslError::Syscall("Invalid send return value".to_string()))?;
10281028
if sent == 0 {
1029-
// No progress - would block
1029+
// No progress - save unsent bytes to pending buffer
1030+
socket
1031+
.pending_tls_output
1032+
.lock()
1033+
.extend_from_slice(&buf[sent_total..]);
10301034
return Err(SslError::WantWrite);
10311035
}
10321036
sent_total += sent;
10331037
}
10341038
Err(e) => {
10351039
if is_blocking_io_error(&e, vm) {
1040+
// Save unsent bytes to pending buffer
1041+
socket
1042+
.pending_tls_output
1043+
.lock()
1044+
.extend_from_slice(&buf[sent_total..]);
10361045
return Err(SslError::WantWrite);
10371046
}
1047+
// For other errors, also save unsent bytes
1048+
socket
1049+
.pending_tls_output
1050+
.lock()
1051+
.extend_from_slice(&buf[sent_total..]);
10381052
return Err(SslError::Py(e));
10391053
}
10401054
}

0 commit comments

Comments
 (0)