Fix dirtsand starting with dead auth daemon.#207
Merged
Conversation
Currently, if DirtSand starts and the auth daemon cannot connect to PostgreSQL, the auth daemon thread exits immediately but the server remains up. This leads to a situation where clients can patch but when they attempt to actually log in, they never get a response because the auth daemon never actually started. There are basically two ways to fix this. One way is to kill the whole process if the database isn't up. This would be workable, but the design of the system doesn't really support the individual daemons communicating back to the DirtSand process itself, except via hacks like `exit(1)`. Instead, I've opted to allow the auth daemon to try deferring initializaion. This allows us to centralize the database connection reset logic and remove all of the manual `check_postgres()` calls.
zrax
approved these changes
Mar 2, 2026
| ST::printf(stderr, "Error connecting to postgres: {}", PQerrorMessage(s_postgres)); | ||
|
|
||
| // If the connection to postgres was successful, initialize the vault here. | ||
| dm_authCheck(false); |
Member
There was a problem hiding this comment.
There's still probably room for improvement here -- for example, if we failed due to an invalid DB config rather than a server issue, we'll just keep spitting out errors on every incoming message and hope the user eventually notices :). But not dropping the thread and continuing silently is a definite improvement, so +1 from me.
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.
Currently, if DirtSand starts and the auth daemon cannot connect to PostgreSQL, the auth daemon thread exits immediately but the server remains up. This leads to a situation where clients can patch but when they attempt to actually log in, they never get a response because the auth daemon never actually started.
There are basically two ways to fix this. One way is to kill the whole process if the database isn't up. This would be workable, but the design of the system doesn't really support the individual daemons communicating back to the DirtSand process itself, except via hacks like
exit(1). Instead, I've opted to allow the auth daemon to try deferring initializaion. This allows us to centralize the database connection reset logic and remove all of the manualcheck_postgres()calls.