-
Notifications
You must be signed in to change notification settings - Fork 63
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
fix(workspace): gracefully handle failing db connections #194
fix(workspace): gracefully handle failing db connections #194
Conversation
} else { | ||
None | ||
} | ||
let pool = connection.get_pool(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of the below is just moved by a tab, because I removed the if let Some(..) = ..
closure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice! Thanks for the cleanup too. Left two comments, let's discuss them in the respective threads 🙏🏼
Regarding the "slowness": I added a Regarding the timeout: I tried to add a deferred log to the console, something that would print "Your connection takes longer than expected…" if it takes >=2s – but that required wrapping the So instead, I added a I also added an AtomicBool that indicates whether we were able to get a I'm not 100% happy with the result; especially the bool feels inelegant. So hit me with your feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the implementation a lot, but the entire user hint story feels like bloat? For now, I think we should either skip this "feedback" entirely or just add it as another "warning" diagnostics? but not sure
agree! I thought about adding it as a warning, but I can also see someone setting their CI to fail on "warn" instead of "error" – and a slow db connection shouldn't be the reason for that. Let's leave it for now; maybe it's a non-issue and most people simply have working connections. I do think it would be nice if we could output logs during and not only after the traversal, but let's descope that for now. |
@psteinroe Also, you're still on vacation for a day, so don't you dare review before tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I am on German grounds again!)
Lgtm! Just have one comment about the timeout 🙏🏼
|
||
/// The connection timeout in seconds. | ||
#[partial(bpaf(long("conn_timeout")))] | ||
pub conn_timeout_secs: Option<u16>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but maybe we can set the default via bpaf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, we should add it to the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with using a bpaf fallback, but the partial
macro requires that the fallback is wrapped in an Option.
If we want to use display_fallback
, we would also need to implement Display for Option<u16>
, but we can't because of the Orphan Rule.
A quick fix is to add the fallback to the comment, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR, we should now be able to run basic diagnostics, even if the workspace can't connect to the Db. I tested it locally with
pg_cli check test.sql
and it seems to work.The basic gist:
Whenever we called
WorkspaceServer::update_settings
, we would configure theDatabaseConnection
for lazy-loading, but eagerly loaded theSchemaCache
.I thought it was weird that we queried the Db in a
update_settings
call, so I refactored the SchemaCache to be lazy-loaded as well.For this, I wrapped the whole thing into a
SchemaCacheManager
which checks if we've already cached the requestedPgPool
's schema, returning guarded handles to the underlyingSchemaCache
.Additional Things
SchemaCacheManager
,DbConnection
, and the async runtime helpers into their own modulescompletions
handler will now return an empty array if we can't connect to the dbconn_timeout_secs
config option, which is by default set to 10 secondsDefault
impl