- Notifications
You must be signed in to change notification settings - Fork905
fix(coderd): fix panics by always checking for non-nil request logger#18228
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
This could lead to strange issues where we expect to find some information in the logs but end up not doing so due to forgetting to include the logger context.
Can we instead introduce at.Logf
adapter incoderdtest
?
Looking at the commit history, it seems this was introduced by@ibetitsmike. Do you have any thoughts on how to proceed based on@johnstcn comment? I'm just looking to fix the test race, but happy to hand this over to someone else if another approach is preferred. |
@mafredri@johnstcn generally the only scenario in which So the only scenario where it fails is if we call the method that tries to log, but doesn't do it through API. An example that was failing for me was provisioner_job_tests which I fixed here:https://github.com/coder/coder/pull/17304/files#diff-a0b103dd31ee53f52c43564220dbada29c0d9147e7210b27cb42e375b08fd947 If we experience flakes I'd try to understand why a given test path fails to run this line:https://github.com/coder/coder/blob/5f7e5d709787ca4e6ec287197f112d56d0eae2c8/coderd/httpmw/loggermw/logger.go#L44C11-L44C28
|
mafredri commentedJun 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Here's a repro:
There was another test as well that failed, also log follower. It's an easy miss to include the request logger when writing a test of this type, so I'm in favor of nil checks tbh as this happens too late and is racy otherwise. |
What if we added another middleware only in tests that immediately fails the test if the request logging middleware is not present when any request comes in? That should allow surfacing this issue quickly. |
Uh oh!
There was an error while loading.Please reload this page.
These panics can happen during tests (racy), saw that some places protect the request logger via non-nil check so fixed all instances.
(Discussion: This seems like a dangerous tool, perhaps a noop type would be better than
nil
to cover our bases, but I did not make that decision here.)