mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Added another lock to protect broker stats
Added another lock to the metrics struct to synchronize accesses to the broker stats. There's a possible race condition if stats are updated at the same time they are being logged.
This commit is contained in:
parent
42e16021c4
commit
06298eec73
2 changed files with 14 additions and 1 deletions
|
@ -39,6 +39,9 @@ type Metrics struct {
|
|||
proxyIdleCount uint
|
||||
clientDeniedCount uint
|
||||
clientProxyMatchCount uint
|
||||
|
||||
//synchronization for access to snowflake metrics
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (s CountryStats) Display() string {
|
||||
|
@ -161,6 +164,7 @@ func (m *Metrics) logMetrics() {
|
|||
}
|
||||
|
||||
func (m *Metrics) printMetrics() {
|
||||
m.lock.Lock()
|
||||
m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), fmt.Sprintf("(%d s)", int(metricsResolution.Seconds())))
|
||||
m.logger.Println("snowflake-ips", m.countryStats.Display())
|
||||
m.logger.Println("snowflake-ips-total", len(m.countryStats.standalone)+
|
||||
|
@ -171,6 +175,7 @@ func (m *Metrics) printMetrics() {
|
|||
m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount))
|
||||
m.logger.Println("client-denied-count", binCount(m.clientDeniedCount))
|
||||
m.logger.Println("client-snowflake-match-count", binCount(m.clientProxyMatchCount))
|
||||
m.lock.Unlock()
|
||||
}
|
||||
|
||||
// Restores all metrics to original values
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue