mirror of https://github.com/golang/go.git
internal/lsp/debug: guard rpc stats with a Mutex
This type was previously guarded implicitly by the global exporter mutex. With that gone, we've started seeing panics due to races in (*rpcs).Metric. Guard it with a mutex. Change-Id: I2a8c670ecfbaee9422e1f1d282b1fedb86b6a5e0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/222300 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
a0897bacdd
commit
8287d625a0
|
|
@ -11,6 +11,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
tlm "golang.org/x/tools/internal/lsp/telemetry"
|
||||
"golang.org/x/tools/internal/telemetry"
|
||||
|
|
@ -42,6 +43,7 @@ var rpcTmpl = template.Must(template.Must(baseTemplate.Clone()).Parse(`
|
|||
`))
|
||||
|
||||
type rpcs struct {
|
||||
mu sync.Mutex
|
||||
Inbound []*rpcStats
|
||||
Outbound []*rpcStats
|
||||
}
|
||||
|
|
@ -91,6 +93,8 @@ type rpcCodeBucket struct {
|
|||
}
|
||||
|
||||
func (r *rpcs) Metric(ctx context.Context, data telemetry.MetricData) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
for i, group := range data.Groups() {
|
||||
set := &r.Inbound
|
||||
if group.Get(tlm.RPCDirection) == tlm.Outbound {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package telemetry
|
||||
|
||||
// Data represents a single point in the time series of a metric.
|
||||
// MetricData represents a single point in the time series of a metric.
|
||||
// This provides the common interface to all metrics no matter their data
|
||||
// format.
|
||||
// To get the actual values for the metric you must type assert to a concrete
|
||||
|
|
|
|||
Loading…
Reference in New Issue