Skip to content

Allow the application to start without a database connection #3572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2021

Conversation

pietroalbini
Copy link
Member

This PR implements the last bit of #3541, making sure the server binary can start without a database connection.

To avoid serving the initial requests without a connection, the server will now wait for 5 seconds at startup to initialize the database connections, and if it can't do that in that timeframe it will treat the database as unhealthy and continue starting up the server.

This is critical to our continued availability, so to make sure this doesn't regress I also implemented a test that fails if a database connection becomes a requirement to start the server again. The test is implemented by starting the server binary with the right environment variables and doing proper HTTP requests to it.

Fixes #3541
r? @jtgeibel

@pietroalbini
Copy link
Member Author

Need to investigate the tests failing later, but the PR is still ready for review. My guess is that CI doesn't have the right environment variables configured.

@pietroalbini pietroalbini force-pushed the broken-start branch 2 times, most recently from 7e5c6f5 to 719d1f2 Compare April 30, 2021 11:07
@jtgeibel
Copy link
Member

jtgeibel commented May 3, 2021

Looks great to me! The tests passed for me locally, but if I comment out either GH_CLIENT_ID or GH_CLIENT_SECRET in my .env then the server fails to start. Interestingly, these can be set to an empty string and the tests will pass.

Eventually we could probably hook GitHub and S3 requests into our existing HTTP recording code, but for now its fine if we just document that these tests should not hit endpoints that could trigger external HTTP requests.

@Turbo87
Copy link
Member

Turbo87 commented May 4, 2021

Eventually we could probably hook GitHub and S3 requests into our existing HTTP recording code

I think GitHub and S3 are exactly what is already hooked up, or am I missing something? 🤔

@jtgeibel
Copy link
Member

jtgeibel commented May 6, 2021

I think GitHub and S3 are exactly what is already hooked up, or am I missing something?

The 2 new ServerBin tests actually boot the server, configured via its environment variables. Our existing tests link to the library crate, and configure an App instances for each test. In particular, those tests configure the S3 uploader (api_protocol) and GitHub API (gh_base_url) to use plaintext HTTP to a per-test proxy. (As far as I can tell, we don't plaintext proxy GitHub OAuth requests in our current tests, because the actual navigation to GitHub happens client side in the frontend.)

My understanding is that for now, if we tried to hit say the crate publish endpoint in a ServerBin test, then the server binary would try to make HTTPS requests to S3 and GitHub using whatever credentials it has available (possibly picking them up from a local .env file). We can't leak test requests out into the wild, but I also don't want to build a configuration switch into release binaries that effectively switches all our outgoing requests to plaintext.

We should probably add an environment variable that disables all outgoing requests, returning an error instead. But I don't think it is necessary to block this PR on that.

@bors
Copy link
Contributor

bors commented May 10, 2021

☔ The latest upstream changes (presumably #3596) made this pull request unmergeable. Please resolve the merge conflicts.

@pietroalbini
Copy link
Member Author

Resolved the conflict and (hopefully!) fixed CI.

@jtgeibel
Copy link
Member

LGTM!! @bors r+

@bors
Copy link
Contributor

bors commented May 14, 2021

📌 Commit 1523948 has been approved by jtgeibel

@bors
Copy link
Contributor

bors commented May 14, 2021

⌛ Testing commit 1523948 with merge 509d7a2...

@bors
Copy link
Contributor

bors commented May 14, 2021

☀️ Test successful - checks-actions
Approved by: jtgeibel
Pushing 509d7a2 to master...

@bors bors merged commit 509d7a2 into rust-lang:master May 14, 2021
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.

Ensure downloads work without a database connection
5 participants