fix: refactor coder logger to allow flush without deadlock#375
Merged
fix: refactor coder logger to allow flush without deadlock#375
Conversation
34365d5 to
cf30d8b
Compare
mtojek
approved these changes
Sep 30, 2024
| closeOnce.Do(func() { | ||
| // Trigger a flush and wait for logs to be sent. | ||
| ls.Flush(uid) | ||
| ctx, cancel := context.WithTimeout(ctx, logSendGracePeriod) |
Member
There was a problem hiding this comment.
nit: should we merge context.WithTimeout and context.WithCancel and use one above?
Member
Author
There was a problem hiding this comment.
It's doable, but I feel their purpose is clearer as-is. We could actually make sendCtx not inherit function ctx instead but it's also pointless because ConnectRPC20 applies ctx to connection, so messages won't go through.
dannykopping
approved these changes
Sep 30, 2024
| metaLogger.Warn(ctx, "Detected Coder version incompatible with AgentAPI v2, falling back to deprecated API", slog.F("coder_version", bi.Version)) | ||
| sendLogs, flushLogs := sendLogsV1(ctx, client, metaLogger.Named("send_logs_v1")) | ||
| return sendLogs, flushLogs, nil | ||
| logger, closer = sendLogsV1(ctx, client, metaLogger.Named("send_logs_v1")) |
Contributor
There was a problem hiding this comment.
Nice 👍 I found those previous names hard to reason about.
| // sendLogsV2 uses the v2 agent API to send logs. Only compatibile with coder versions >= 2.9. | ||
| func sendLogsV2(ctx context.Context, dest agentsdk.LogDest, ls coderLogSender, l slog.Logger) (Func, func()) { | ||
| func sendLogsV2(ctx context.Context, dest agentsdk.LogDest, ls coderLogSender, l slog.Logger) (logger Func, closer func()) { | ||
| sendCtx, sendCancel := context.WithCancel(ctx) |
Contributor
There was a problem hiding this comment.
Should sendCancel be deferred, too?
Member
Author
There was a problem hiding this comment.
Nope, we want to keep this context alive until we've flushed or hit the timeout in the closer function.
1470637 to
5243969
Compare
mafredri
added a commit
that referenced
this pull request
Sep 30, 2024
mafredri
added a commit
that referenced
this pull request
Sep 30, 2024
mafredri
added a commit
that referenced
this pull request
Oct 2, 2024
(cherry picked from commit 8170323)
mafredri
added a commit
that referenced
this pull request
Oct 2, 2024
mafredri
added a commit
that referenced
this pull request
Oct 2, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #364