Repository navigation
Conversation
So that tests can build the server exactly as startup does. No change in behavior.
The storage (and auth) backend was created once at startup, so every client used the same database connection: on POSIX each forked child inherited it, and on Windows every thread shared it. With two clients at once, their queries and results interleaved -- clients got each other's rows (e.g. an author name where an article number was expected), SQL built from the wrong results, or MySQLdb's 'connection is already in use from another thread'. The server now holds factories, and each connection creates its own storage backend (in the forked child on POSIX) and, on first use, its own auth backend; both are closed when the connection ends. If the database can't be reached, the client gets '400 service temporarily unavailable'. build_server() still connects once at startup, so a bad configuration fails immediately. tests/integration/test_concurrency.py runs 6 clients at once against the server as build_server() creates it, forking and threading, on MySQL and PostgreSQL; before this change 5-6 of the 6 clients failed in every combination.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
The storage and auth backends were created once at startup, so every client used the same database connection. On POSIX each forked child inherited it, and on Windows every thread shared it. With two clients at once, their queries and results interleaved. A new test reproduced it with 6 simultaneous clients, and 5–6 of the 6 failed in every combination:
ValueError: invalid literal for int() with base 10: 'Alice'where an article number was expected'1)MySQLdb.ProgrammingError: This connection is already in use from another threadThe fix
400 service temporarily unavailableinstead of a crash.build_server()still connects once at startup, so a bad configuration fails immediately.build_server()(first commit, no behavior change), so the tests build the server exactly as production does.Testing
tests/integration/test_concurrency.py: 6 clients × 15 rounds at once, forking and threading, on MySQL and PostgreSQL. The server runs in a separate process, so a driver crash fails the test instead of killing pytest. It also checks the server log, to confirm all the requests reached the server.400for an unreachable database, auth created only on login, and the startup check.