-
Notifications
You must be signed in to change notification settings - Fork 1
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: indefinite function runs inside mutex lock #372
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a9fcd6
fix: indefinite function runs inside mutex lock
Siddddarth fd6697e
cleanup
Siddddarth 1b8dd50
fixup! cleanup
Siddddarth 54381be
Merge branch 'main' into fix.LockAfterIndefiniteReturn
fracasula 53c85ec
review comments
Siddddarth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,17 +50,28 @@ | |
goFactory.Go(func() { | ||
if err != nil { | ||
s.logger.Info("retrying StatsD client creation in the background...") | ||
s.state.client.statsdMu.Lock() | ||
s.state.client.statsd, err = s.getNewStatsdClientWithExpoBackoff(ctx, s.state.conn, s.statsdConfig.statsdTagsFormat(), s.statsdConfig.statsdDefaultTags()) | ||
s.state.client.statsdMu.Unlock() | ||
var c *statsd.Client | ||
c, err = s.getNewStatsdClientWithExpoBackoff( | ||
ctx, | ||
s.state.conn, | ||
s.statsdConfig.statsdTagsFormat(), | ||
s.statsdConfig.statsdDefaultTags(), | ||
) | ||
if err != nil { | ||
s.config.enabled.Store(false) | ||
s.logger.Errorf("error while creating new StatsD client, giving up: %v", err) | ||
} else { | ||
s.state.clientsLock.Lock() | ||
s.state.client.statsd = c | ||
for _, client := range s.state.pendingClients { | ||
client.statsdMu.Lock() | ||
client.statsd = s.state.client.statsd.Clone(s.state.conn, s.statsdConfig.statsdTagsFormat(), s.statsdConfig.statsdDefaultTags(), statsd.Tags(client.tags...), statsd.SampleRate(client.samplingRate)) | ||
client.statsd = s.state.client.statsd.Clone( | ||
s.state.conn, | ||
s.statsdConfig.statsdTagsFormat(), | ||
s.statsdConfig.statsdDefaultTags(), | ||
statsd.Tags(client.tags...), | ||
statsd.SampleRate(client.samplingRate), | ||
) | ||
client.statsdMu.Unlock() | ||
} | ||
|
||
|
@@ -104,7 +115,7 @@ | |
|
||
func (s *statsdStats) collectPeriodicStats(goFactory GoRoutineFactory) { | ||
gaugeFunc := func(key string, val uint64) { | ||
s.state.client.statsd.Gauge("runtime_"+key, val) | ||
s.NewStat("runtime_"+key, GaugeType).Gauge(val) | ||
} | ||
s.state.rc = newRuntimeStatsCollector(gaugeFunc) | ||
s.state.rc.PauseDur = time.Duration(s.config.periodicStatsConfig.statsCollectionInterval) * time.Second | ||
|
@@ -152,7 +163,7 @@ | |
|
||
// NewStat creates a new Measurement with provided Name and Type | ||
func (s *statsdStats) NewStat(name, statType string) (m Measurement) { | ||
return s.newStatsdMeasurement(name, statType, s.state.client) | ||
return s.internalNewTaggedStat(name, statType, nil, 1) | ||
} | ||
|
||
func (s *statsdStats) NewTaggedStat(Name, StatType string, tags Tags) (m Measurement) { | ||
|
@@ -200,7 +211,13 @@ | |
taggedClient = &statsdClient{samplingRate: samplingRate, tags: tagVals} | ||
if s.state.connEstablished { | ||
taggedClient.statsdMu.Lock() | ||
taggedClient.statsd = s.state.client.statsd.Clone(s.state.conn, s.statsdConfig.statsdTagsFormat(), s.statsdConfig.statsdDefaultTags(), statsd.Tags(tagVals...), statsd.SampleRate(samplingRate)) | ||
taggedClient.statsd = s.state.client.statsd.Clone( | ||
s.state.conn, | ||
s.statsdConfig.statsdTagsFormat(), | ||
s.statsdConfig.statsdDefaultTags(), | ||
statsd.Tags(tagVals...), | ||
statsd.SampleRate(samplingRate), | ||
) | ||
taggedClient.statsdMu.Unlock() | ||
} else { | ||
// new statsd clients will be created when connection is established for all pending clients | ||
|
@@ -297,9 +314,8 @@ | |
} | ||
|
||
// ready returns true if the statsd client is ready to be used (not nil). | ||
// | ||
// statsdMu.RLock should be held when calling this method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment might be useful on |
||
func (sc *statsdClient) ready() bool { | ||
sc.statsdMu.RLock() | ||
defer sc.statsdMu.RUnlock() | ||
|
||
return sc.statsd != nil | ||
} |
This file contains 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
Oops, something went wrong.
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.
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.
There is no need to lock here given that we just created the client and it's not a key on any of the maps, right?