Skip to content

Tests on Windows: a stream whose peer aborted the connection, and Pyjo.Prove before Python 3.15 #545

Closed

Description

@dex4er

The problem

Three failures of the suite of Pyjoyment on Windows, in the workflow Tests of Pyjo-Reactor-Winloop, which runs it on Pyjo.Reactor.Winloop with CPython 3.12 to 3.15 and 3.15t on windows-2025:

A stream whose peer aborted the connection is not closed

t/Pyjo/JSON_RPC.py, subtest Calls of a closed peer, fails on every run, on every Python:

#   Failed test 'rejected'
#     Structures begin differing at:
#          got[0] = Does not exist
#     expected[0] = 'Connection closed'

The client writes its call to the socket whose peer is closed, before it reads, and the recv that follows raises ConnectionAbortedError, WinError 10053, WSAECONNABORTED. Pyjo.IOLoop.Stream._read_handle closes the stream on ConnectionResetError and BrokenPipeError only, so it emits error, which Pyjo.IOLoop.Messages emits again with no subscriber, so emit raises before .close(). The stream stays, and the reactor calls its watcher again and again:

Pyjo.Reactor.Winloop.Pyjo_Reactor_Winloop: I/O watcher failed: Pyjo.IOLoop.Messages.Pyjo_IOLoop_Messages: [WinError 10053] An established connection was aborted by the software in your host machine

until the timer of the test stops the loop. On Pyjo.Reactor.Asyncio the read comes first, gets the end of the stream, and the test passes; a reactor that runs the writer first gets the error of Windows.

Pyjo.Prove: the summary in Markdown read in the encoding of the locale

t/Pyjo/Prove.py, subtest Summary in Markdown, fails on every run with Python 3.12, 3.13 and 3.14:

    like_ok(f.read(), r'^### Pyjo\.Prove\n', 'written over')
  File "...\Lib\encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 60: character maps to <undefined>

Pyjo.Prove writes the summary in UTF-8, and the test reads it back with open(summary), in the encoding of the locale, which is cp1252 on Windows before Python 3.15, where UTF-8 is the default (PEP 686). The job prove-windows of Pyjoyment runs the Python of mise, 3.15, so it does not see it.

Pyjo.Prove: a process of the script holds the temporary directory

t/Pyjo/Prove.py, subtest Capture the standard error, fails now and then, in 4 jobs of 15 in three runs:

    out, err, code = prove_stderr('--capture-stderr', '--timeout', '2', 'child.py')
  File "...\t\Pyjo\Prove.py", line 141, in prove_files
    with tempfile.TemporaryDirectory() as tmp:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpvlgyl54m'

The process that child.py starts keeps its output open, which is what the subtest tests, and it is still running in the temporary directory when TemporaryDirectory removes it, which Windows refuses.

How it was found

The workflow Tests of Pyjo-Reactor-Winloop with Pyjoyment of main at 1d48088 (pyjoyment/Pyjo-Reactor-Winloop#3), and runs on Windows 11 with Python 3.15. The first failure is the same with Pyjoyment 25fbbfa, before #534.

A possible fix

  • Pyjo.IOLoop.Stream._read_handle: ConnectionAbortedError as a close, as ConnectionResetError and BrokenPipeError are. With it, t/Pyjo/JSON_RPC.py passes on Pyjo.Reactor.Winloop.
  • t/Pyjo/Prove.py: the summary read with encoding='utf-8'.
  • t/Pyjo/Prove.py: the temporary directory of prove_files removed after the processes of the script end, or with ignore_cleanup_errors=True.

Activity

  1. dex4er commented on Nov 5, 2026

    @dex4er
    CollaboratorAuthor

    More of the third failure, the temporary directory of t/Pyjo/Prove.py, from the Tests of pyjoyment/Pyjo-Reactor-Winloop#4 (run):

    • Capture the standard error failed with WinError 32 on 3.13, 3.15 and 3.15t, 3 jobs of 5 in that run.
    • With 3.14, Timeout failed instead, at the process of the script is killed with it: prove('--timeout', '2', 'child.py') took 30 seconds or more, so the process that child.py starts, time.sleep(60), was not killed with the script.

    So on the runner of windows-2025 the process of the script outlives it, not only for the moment it takes to end: it is not killed with the job, or not in the job at all. Then TemporaryDirectory cannot remove its working directory. It does not happen on Windows 11 here, where the processes of the job are gone right after TerminateJobObject. Possible causes, to check on the runner: _job returns None, as AssignProcessToJobObject fails for a process in the job of the runner, and _kill falls back to process.kill() of the script alone; or the job of the runner lets the processes of its processes break away from the job of the script.

  2. dex4er commented on Nov 5, 2026

    @dex4er
    CollaboratorAuthor

    Fixed in #547 (a stream whose peer aborted the connection, and the report of Pyjo.Prove on the standard output in UTF-8) and #556 (a script of Windows joins the job of the harness before it runs, so the process of child.py ends with it).

  3. added this to the 0.3.0 milestone on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions