Skip to content

Wait until consumed response handlers finish - #539

Open
ShahadatTest wants to merge 3 commits into
csernazs:masterfrom
ShahadatTest:fix/wait-for-handler-completion
Open

ShahadatTest wants to merge 3 commits into
csernazs:masterfrom
ShahadatTest:fix/wait-for-handler-completion

Conversation

@ShahadatTest

@ShahadatTest ShahadatTest commented Nov 1, 2026 •

Copy link
Copy Markdown

HTTPServer.wait() can report success while the final ordered or oneshot response callback is still running: completion is signalled when the expectation is removed. Track callbacks that have been consumed but are still running and signal only after the final one exits. Synchronize selection and callback counts while leaving response callbacks outside the lock, so concurrent responses can still run.

The regression tests send real HTTP requests through http.client.HTTPConnection to a running server. One test keeps the final response callback open after the request arrives. The threaded-server test starts two requests, lets the second finish and verifies that wait() does not report success while the first callback remains active. This second case is why moving the notification to the end of the last matched dispatch alone is insufficient: an earlier callback can still be running. Both tests cover ordered and oneshot expectations. Events coordinate callback entry/release; no direct dispatch calls or client thread pools are used.

These are code-inspection reproductions of a client making requests asynchronously while the test waits for its server callbacks. No personal production incident is claimed.

4 regressions using real HTTP connections fail on untouched upstream. All 22 wait/ordered/oneshot/handler-error/threaded tests pass on Python 3.11/3.12. Ruff, Black, isort, mypy (7 source files) and diff checks pass. The complete suite was not completed locally; the earlier full run was stopped during the long Windows run.

AI assistance: OpenAI Codex found this by code inspection, implemented and tested it at the account owner’s request ("15 TA koro aro"). No independent human review is claimed.

@csernazs

csernazs commented Nov 1, 2026

Copy link
Copy Markdown
Owner

hi @ShahadatTest ,

Do you have a more real-life example for this error? The tests written are not from this world, I think nobody calls dispatch on the server and nobody uses threadpool.

For the first sight, it seems just putting the _update_waiting_result() call to the end of the dispatch (and to the expect branches as well) would solve the issue.

Zsolt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants