Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
mafredri wants to merge1 commit intomain
base:main
Choose a base branch
Loading
frommafredri/fix-coderd-panic-request-log

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedJun 4, 2025
edited
Loading

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 thannil to cover our bases, but I did not make that decision here.)

@mafredrimafredri self-assigned thisJun 4, 2025
Copy link
Member

@johnstcnjohnstcn left a 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?

@mafredri
Copy link
MemberAuthor

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.

@ibetitsmike
Copy link
Contributor

@mafredri@johnstcn generally the only scenario in whichrequestLogger isnil is if the request circumvents our API Logger middleware. It's responsible for attachingRequestLogger to context.

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

RequestLogger is useful to debug issues with long lived connections, so it's not critical to have that information 100% of the time, but@deansheather was the one that initially asked me to remove thosenil checks (I had them in the first implementation).

@mafredri
Copy link
MemberAuthor

mafredri commentedJun 4, 2025
edited
Loading

Here's a repro:

go test ./coderd -run=Test_logFollower_completeBeforeFollow -v -race -count=10

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.

@johnstcn
Copy link
Member

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn left review comments

@dannykoppingdannykoppingAwaiting requested review from dannykopping

At least 1 approving review is required to merge this pull request.

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mafredri@ibetitsmike@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp