Skip to content

Commit 8a43b8e

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 21a68f2 commit 8a43b8e

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

crates/stdlib/src/rustls.rs

Lines changed: 30 additions & 3 deletions
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::{
@@ -2948,9 +2950,34 @@ impl Io {
29482950
Ok(value) => Ok(value),
29492951

29502952
Err(err) => match err.kind() {
2951-
std::io::ErrorKind::Other => Err(SslError::Py(
2952-
io.error.take().expect("BUG: Io.error is not set"),
2953-
)),
2953+
std::io::ErrorKind::Other => {
2954+
let err = io.error.take().expect("BUG: Io.error is not set");
2955+
2956+
// This is an ugly hack for test.test_ssl.ThreadedTests.test_wrong_cert_tls*
2957+
const ERRNO_INTO_ECONNRESET: &[i32] = &[
2958+
errno::errors::ECONNRESET,
2959+
errno::errors::EPIPE,
2960+
errno::errors::ECONNABORTED,
2961+
];
2962+
if err.fast_isinstance(vm.ctx.exceptions.os_error)
2963+
&& err
2964+
.as_object()
2965+
.get_attr("errno", vm)
2966+
.and_then(|e| e.try_into_value::<i32>(vm))
2967+
.is_ok_and(|e| ERRNO_INTO_ECONNRESET.contains(&e))
2968+
{
2969+
Err(SslError::Py(
2970+
vm.new_os_subtype_error(
2971+
vm.ctx.exceptions.connection_reset_error.to_owned(),
2972+
Some(errno::errors::ECONNRESET),
2973+
"Connection reset by peer",
2974+
)
2975+
.upcast(),
2976+
))
2977+
} else {
2978+
Err(SslError::Py(err))
2979+
}
2980+
}
29542981

29552982
std::io::ErrorKind::InvalidData => {
29562983
// ConnectionCommon::complete_io() wraps TLS processing errors in InvalidData.

0 commit comments

Comments
 (0)