Skip to content

Commit bb57724

Browse files
authored
flush on WantWrite (#6717)
1 parent f9e2f9d commit bb57724

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/stdlib/src/ssl/compat.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,16 +1237,21 @@ fn handle_handshake_complete(
12371237
}
12381238
} else if conn.wants_write() {
12391239
// Send all pending data (e.g., TLS 1.3 NewSessionTicket) to socket
1240-
// Best-effort: WantWrite means socket buffer full, pending data will be
1241-
// sent in subsequent read/write calls. Don't fail handshake for this.
1240+
// Must drain ALL rustls buffer - don't break on WantWrite
12421241
while conn.wants_write() {
12431242
let tls_data = ssl_write_tls_records(conn)?;
12441243
if tls_data.is_empty() {
12451244
break;
12461245
}
12471246
match send_all_bytes(socket, tls_data, vm, None) {
12481247
Ok(()) => {}
1249-
Err(SslError::WantWrite) => break,
1248+
Err(SslError::WantWrite) => {
1249+
// Socket buffer full, data saved to pending_tls_output
1250+
// Flush pending and continue draining rustls buffer
1251+
socket
1252+
.blocking_flush_all_pending(vm)
1253+
.map_err(SslError::Py)?;
1254+
}
12501255
Err(e) => return Err(e),
12511256
}
12521257
}
@@ -1256,6 +1261,7 @@ fn handle_handshake_complete(
12561261
// TLS 1.3 Finished must reach server before handshake is considered complete
12571262
// Without this, server may not process application data
12581263
if !socket.is_bio_mode() {
1264+
// Flush pending_tls_output to ensure all TLS data reaches the server
12591265
socket
12601266
.blocking_flush_all_pending(vm)
12611267
.map_err(SslError::Py)?;

0 commit comments

Comments
 (0)