diff --git a/Cargo.lock b/Cargo.lock index 79cfbee8e5..4a9054e6ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1318,7 +1318,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1", + "foreign-types-shared", ] [[package]] @@ -1327,12 +1327,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "foreign-types-shared" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" - [[package]] name = "fs_extra" version = "1.3.0" @@ -3605,7 +3599,7 @@ dependencies = [ "dyn-clone", "flame", "flate2", - "foreign-types-shared 0.3.1", + "foreign-types-shared", "gethostname", "hex", "hmac 0.12.1", diff --git a/Cargo.toml b/Cargo.toml index f298961108..3100baf279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -202,7 +202,8 @@ exitcode = "1.1.2" flame = "0.2.2" flamer = "0.5" flate2 = { version = "1.1.9", default-features = false } -foreign-types-shared = "0.3.1" +# Bump only when the openssl crate bumps it +foreign-types-shared = "0.1" gethostname = "1.0.2" getrandom = { version = "0.3", features = ["std"] } glob = "0.3" diff --git a/crates/stdlib/src/openssl.rs b/crates/stdlib/src/openssl.rs index f559726c22..03b7c0d0bb 100644 --- a/crates/stdlib/src/openssl.rs +++ b/crates/stdlib/src/openssl.rs @@ -65,7 +65,7 @@ mod _ssl { LazyLock, PyMappedRwLockReadGuard, PyMutex, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard, }, - socket::{self, PySocket}, + socket::{self, PySocket, SockWaitKind, sock_wait}, vm::{ AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, builtins::{ @@ -2292,7 +2292,12 @@ mod _ssl { self.0.get_timeout().map(|d| Instant::now() + d) } - fn select(&self, needs: SslNeeds, deadline: &SocketDeadline) -> SelectRet { + fn select( + &self, + needs: SslNeeds, + deadline: &SocketDeadline, + vm: &VirtualMachine, + ) -> SelectRet { let sock = match self.0.sock_opt() { Some(s) => s, None => return SelectRet::Closed, @@ -2307,15 +2312,11 @@ mod _ssl { Err(true) => None, // Blocking: no timeout, wait indefinitely Err(false) => return SelectRet::Nonblocking, }; - let res = socket::sock_select( - &sock, - match needs { - SslNeeds::Read => socket::SelectKind::Read, - SslNeeds::Write => socket::SelectKind::Write, - }, - timeout, - ); - match res { + let wait_kind = match needs { + SslNeeds::Read => SockWaitKind::Read, + SslNeeds::Write => SockWaitKind::Write, + }; + match sock_wait(&*sock, wait_kind, timeout, vm) { Ok(true) => SelectRet::TimedOut, _ => SelectRet::Ok, } @@ -2325,13 +2326,14 @@ mod _ssl { &self, err: &ssl::Error, deadline: &SocketDeadline, + vm: &VirtualMachine, ) -> (Option, SelectRet) { let needs = match err.code() { ssl::ErrorCode::WANT_READ => Some(SslNeeds::Read), ssl::ErrorCode::WANT_WRITE => Some(SslNeeds::Write), _ => None, }; - let state = needs.map_or(SelectRet::Ok, |needs| self.select(needs, deadline)); + let state = needs.map_or(SelectRet::Ok, |needs| self.select(needs, deadline, vm)); (needs, state) } } @@ -2850,7 +2852,7 @@ mod _ssl { break; } // Wait briefly for peer's close_notify before retrying - match socket_stream.select(SslNeeds::Read, &deadline) { + match socket_stream.select(SslNeeds::Read, &deadline, vm) { SelectRet::TimedOut => { return Err(socket::timeout_error_msg( vm, @@ -2888,7 +2890,7 @@ mod _ssl { }; // Wait on the socket - match socket_stream.select(needs, &deadline) { + match socket_stream.select(needs, &deadline, vm) { SelectRet::TimedOut => { let msg = if err == sys::SSL_ERROR_WANT_READ { "The read operation timed out" @@ -2984,7 +2986,7 @@ mod _ssl { let (needs, state) = stream .get_ref() .expect("handshake called in bio mode; should only be called in socket mode") - .socket_needs(&err, &timeout); + .socket_needs(&err, &timeout, vm); match state { SelectRet::TimedOut => { // Clean up SNI ex_data before returning error @@ -3038,7 +3040,7 @@ mod _ssl { .get_ref() .expect("write called in bio mode; should only be called in socket mode"); let timeout = socket_ref.timeout_deadline(); - let state = socket_ref.select(SslNeeds::Write, &timeout); + let state = socket_ref.select(SslNeeds::Write, &timeout, vm); match state { SelectRet::TimedOut => { return Err(socket::timeout_error_msg( @@ -3058,7 +3060,7 @@ mod _ssl { let (needs, state) = stream .get_ref() .expect("write called in bio mode; should only be called in socket mode") - .socket_needs(&err, &timeout); + .socket_needs(&err, &timeout, vm); match state { SelectRet::TimedOut => { return Err(socket::timeout_error_msg( @@ -3229,7 +3231,7 @@ mod _ssl { let (needs, state) = stream .get_ref() .expect("read called in bio mode; should only be called in socket mode") - .socket_needs(&err, &timeout); + .socket_needs(&err, &timeout, vm); match state { SelectRet::TimedOut => { return Err(socket::timeout_error_msg(