Repository navigation
collector: fix transaction handling, guard type assertions - #245
Conversation
8e6e57b to
a201116
Compare
BramGruneir
left a comment
There was a problem hiding this comment.
I'm kind of confused by a good chunk of the changes.
| return err | ||
| } | ||
| defer tx.Commit(ctx) | ||
| defer func() { |
There was a problem hiding this comment.
You're commiting inside the defer? This seems dangrous.
| } | ||
| _, err := s.scheduler.Every(s.config.Refresh). | ||
| Do(func() { | ||
| if !s.refreshMu.TryLock() { |
There was a problem hiding this comment.
why do you need a new mutex? Can't you just use the original?
There was a problem hiding this comment.
I reworked the logic, so I can use just one mutex.
…ad code Fix collectLocked to use a single deferred rollback/commit based on error state instead of fragile explicit rollback calls. Guard bare type assertions in counterAdd, clearObsoleteGauges, and cache eviction to prevent panics. Remove unused `first` field and unused `name` parameter from gaugeSet. Replace manual inUse flag with TryLock in Collect, and add refreshRunning mutex guard in server Start. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1035860 to
f3b5a1f
Compare
sravotto
left a comment
There was a problem hiding this comment.
Thanks - please take another look.
| } | ||
| _, err := s.scheduler.Every(s.config.Refresh). | ||
| Do(func() { | ||
| if !s.refreshMu.TryLock() { |
There was a problem hiding this comment.
I reworked the logic, so I can use just one mutex.
| return err | ||
| } | ||
| defer tx.Commit(ctx) | ||
| defer func() { |
BramGruneir
left a comment
There was a problem hiding this comment.
Looks much better, just a few minor comments.
| s.mu.Unlock() | ||
| err := s.Refresh(ctx) | ||
| if err != nil { | ||
| log.Errorf("Error refreshing metrics %s", err.Error()) |
There was a problem hiding this comment.
This error is just logged and ignored right?
And might as well combine it with the row above.
| return | ||
| } | ||
| defer s.refreshMu.Unlock() | ||
| s.mu.Unlock() |
There was a problem hiding this comment.
You want to unlock before the refresh?
There was a problem hiding this comment.
I guess you could make a locked version of it too. To avoid the lock flapping.
BramGruneir
left a comment
There was a problem hiding this comment.
That was supposed to be a LGTM with minor comments.
f3b5a1f to
805caf5
Compare
Fix collectLocked to use a single deferred rollback/commit based on error state instead of fragile explicit rollback calls. Guard bare type assertions in counterAdd, clearObsoleteGauges, and cache eviction to prevent panics. Remove unused
firstfield and unusednameparameter from gaugeSet. Replace manual inUse flag with TryLock in Collect, and add refreshRunning mutex guard in server Start.