Fix race on startup with HTTP server#5107
Conversation
|
apologies for reviewing late; for this type of bug (which sadly it's not the first time we're running into), I'd love us to think about a robust solution of type do-it-once-and-forget. Right now we have to update every HTTP endpoint, so I worry whoever is adding a new HTTP endpoint later is going to forget to add the guard (I totally would). We also depend on the exact booting sequence - e.g. ideally CommandHandler doesn't care about the state of Herder - that sequence can change anyway (and it has in the past). Maybe we can do something simpler?
This is assuming consumers actually care about if the endpoint is reachable. To my knowledge, many search for things like "Synced!" in the |
| { | ||
| mBucketListSnapshots[std::this_thread::get_id()] = | ||
| bucketSnapshotManager.copySearchableLiveBucketListSnapshot(); | ||
| auto [live, hotArchive] = |
There was a problem hiding this comment.
just curious - what's the motivation behind this specific change?
Description
Resolves #5099
This PR adds a check to HTTP endpoints and exits early if core is not in the correct state to service the endpoint. I've audited the endpoints and divided them into three categories:
Ledger State Dependent Endpoints (i.e. anything with a LedgerHeader or BucketList dependency). Here, we check that LedgerManager is not in
LM_BOOTING_STATEsuch that there is some valid LCL state to query. These endpoints include:Herder Dependent Endpoints. These don't need ledger state, but require overlay and herder to be initialized:
No dependencies. These include all test-only endpoints for simplicity, as well as diagnostic info that should probably always be live, such as /metrics and /ll.
I thought about just delaying starting the endpoint (like the comment initially mentioned), but given the current length of our startup time, we need endpoints like /metrics available at a minimum. It is also probably better from a consumer view for captive-core to reply with a "not ready" status instead of less graceful errors.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)