mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-17 10:22:56 +00:00
The list of endpoints was loaded by scanning the endpoints directory, whenever you started 'neon_local'. If you ran two 'neon_local endpoint create' commands concurrently, one of them might fail because of the other half-finished endpoint creation. There might be a directory without the endpoint.json file, for example, or a half-written endpoint.json file. Most commands don't need the full list of endpoints, however, so only load that when it's needed. In particular, it is now possible to run two "neon_local endpoint create" commands in parallel, if you explicitly assign a port to both. (If you let neon_local assign the port, it needs to check all the other endpoints to decide what ports are free.) Another race condition was with the branch-name mappings. They were previously stored in the 'config' file, which would also fail if two 'neon_local' commands tried to change it at the same time. To fix that race condition, use advisory file lock to coordinate access to the branch-name mappings, and only read/modify that file in commands that actually need the mappings. While at it, move the mappings to a separate 'branch_name_mappings.json' file. The motivation for these changes is that I wanted to create a python test that creates lots of tenants concurrently. Without these changes, the concurrent tenant creations would often hit these 'neon_local' race conditions and fail. 'neon_local' is still not concurrency-safe in general, but this is a good start.