File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -2851,10 +2851,18 @@ mod _ssl {
28512851 }
28522852 // Wait briefly for peer's close_notify before retrying
28532853 match socket_stream. select ( SslNeeds :: Read , & deadline) {
2854- SelectRet :: TimedOut => break , // Timeout waiting for peer
2855- SelectRet :: Closed => break , // Socket closed
2854+ SelectRet :: TimedOut => {
2855+ return Err ( vm. new_exception_msg (
2856+ vm. ctx . exceptions . timeout_error . to_owned ( ) ,
2857+ "The read operation timed out" . to_owned ( ) ,
2858+ ) ) ;
2859+ }
2860+ SelectRet :: Closed => {
2861+ return Err ( socket_closed_error ( vm) ) ;
2862+ }
28562863 SelectRet :: Nonblocking => {
2857- // Non-blocking, just continue
2864+ // Non-blocking socket: return SSLWantReadError
2865+ return Err ( create_ssl_want_read_error ( vm) . upcast ( ) ) ;
28582866 }
28592867 SelectRet :: Ok => {
28602868 // Data available, continue to retry
Original file line number Diff line number Diff line change @@ -4124,7 +4124,16 @@ mod _ssl {
41244124 // Non-blocking: return immediately after sending close_notify.
41254125 // Don't wait for peer's close_notify to avoid blocking.
41264126 drop ( conn_guard) ;
4127- let _ = self . flush_pending_tls_output ( vm, None ) ;
4127+ // Best-effort flush; WouldBlock is expected in non-blocking mode.
4128+ // Other errors indicate close_notify may not have been sent,
4129+ // but we still complete shutdown to avoid inconsistent state.
4130+ if let Err ( e) = self . flush_pending_tls_output ( vm, None ) {
4131+ if !is_blocking_io_error ( & e, vm) {
4132+ // Unexpected error - close_notify may not have been sent.
4133+ // Still complete shutdown to avoid leaving socket in
4134+ // inconsistent state.
4135+ }
4136+ }
41284137 * self . shutdown_state . lock ( ) = ShutdownState :: Completed ;
41294138 * self . connection . lock ( ) = None ;
41304139 return Ok ( self . sock . clone ( ) ) ;
You can’t perform that action at this time.
0 commit comments