Skip to content

Commit b6afc8e

Browse files
committed
Workaround for test.test_ssl.ThreadedTests.test_wrong_cert_tls*
Failure: 2026-06-01T20:33:22.6137502Z ====================================================================== 2026-06-01T20:33:22.6138687Z FAIL: test_wrong_cert_tls13 (test.test_ssl.ThreadedTests.test_wrong_cert_tls13) 2026-06-01T20:33:22.6139079Z ---------------------------------------------------------------------- 2026-06-01T20:33:22.6139922Z ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine. (os error 10053) 2026-06-01T20:33:22.6140076Z 2026-06-01T20:33:22.6140508Z During handling of the above exception, another exception occurred: 2026-06-01T20:33:22.6140757Z 2026-06-01T20:33:22.6141051Z Traceback (most recent call last): 2026-06-01T20:33:22.6141607Z File "D:\a\RustPython\RustPython\Lib\test\test_ssl.py", line 238, in wrapper 2026-06-01T20:33:22.6141895Z return func(*args, **kw) 2026-06-01T20:33:22.6142621Z File "D:\a\RustPython\RustPython\Lib\test\test_ssl.py", line 3267, in test_wrong_cert_tls13 2026-06-01T20:33:22.6142922Z with self.assertRaisesRegex( 2026-06-01T20:33:22.6143512Z ~~~~~~~~~~~~~~~~~~~~~~^ 2026-06-01T20:33:22.6143779Z OSError, 2026-06-01T20:33:22.6144033Z ^^^^^^^^ 2026-06-01T20:33:22.6144283Z ...<2 lines>... 2026-06-01T20:33:22.6144550Z 'Broken pipe' 2026-06-01T20:33:22.6144813Z ^^^^^^^^^^^^^ 2026-06-01T20:33:22.6145053Z ): 2026-06-01T20:33:22.6145328Z ^ 2026-06-01T20:33:22.6146900Z AssertionError: "alert unknown ca|EOF occurred|TLSV1_ALERT_UNKNOWN_CA|closed by the remote host|Connection reset by peer|Broken pipe" does not match "[WinError 10053] An established connection was aborted by the software in your host machine. (os error 10053)" There are two problems here: 1) WSAECONNABORTED is reported by some socket operation but test case checks only for stringified WSAECONNRESET. Both test_wrong_cert_tls* tests check for various kinds of connection-related errors so I suppose that those tests are problematic even in cpython (there are comments about this too). 2) RustPython produces wrong strings for OSError. cpython has a separate mapping for this: https://github.com/python/cpython/blob/5607950ef232dad16d75c0cf53101d9649d89115/Modules/errnomodule.c
1 parent 09abb5d commit b6afc8e

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

crates/stdlib/src/rustls.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ use x509_parser::{
7575
x509::X509Name,
7676
};
7777

78+
use rustpython_host_env::errno;
79+
7880
use crate::{
7981
common::lock::LazyLock,
8082
vm::{
@@ -2844,7 +2846,30 @@ impl Io {
28442846

28452847
Err(err) => match err.kind() {
28462848
std::io::ErrorKind::Other => {
2847-
Err(io.error.take().expect("BUG: Io.error is not set"))
2849+
let err = io.error.take().expect("BUG: Io.error is not set");
2850+
2851+
// This is an ugly hack for test.test_ssl.ThreadedTests.test_wrong_cert_tls*
2852+
const ERRNO_INTO_ECONNRESET: &[i32] = &[
2853+
errno::errors::ECONNRESET,
2854+
errno::errors::EPIPE,
2855+
errno::errors::ECONNABORTED,
2856+
];
2857+
if err
2858+
.as_object()
2859+
.get_attr("errno", vm)
2860+
.and_then(|e| e.try_into_value::<i32>(vm))
2861+
.is_ok_and(|e| ERRNO_INTO_ECONNRESET.contains(&e))
2862+
{
2863+
Err(vm
2864+
.new_os_subtype_error(
2865+
vm.ctx.exceptions.connection_reset_error.to_owned(),
2866+
Some(errno::errors::ECONNRESET),
2867+
"Connection reset by peer",
2868+
)
2869+
.upcast())
2870+
} else {
2871+
Err(err)
2872+
}
28482873
}
28492874

28502875
std::io::ErrorKind::InvalidData => {

0 commit comments

Comments
 (0)