Skip to content
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

Deadlock when using invalid metric name with prometheus reporter #88

Open
aud10slave opened this issue Dec 28, 2018 · 0 comments
Open

Comments

@aud10slave
Copy link

If prometheus reporter is used and and an invalid metrics name is supplied then the scope.Close goes into a deadlock.

Example code:

var reporter tally.CachedStatsReporter
promReporter := tallyprom.NewReporter(tallyprom.Options{})
reporter = tallymulti.NewMultiCachedReporter(promReporter)
scope, closer := tally.NewRootScope(
	tally.ScopeOptions{
		Prefix:         "test",
		Tags:           map[string]string{},
		CachedReporter: reporter,
	},
	1 * time.Second)
defer closer.Close()

// use the scope 
g := scope.Gauge("invalid-name")
fmt.Println("gauge created")

The Println never gets called. Looking at the goroutine dump here's what happens

  1. scope.Gauge acquires a write lock on the gauge mutex

  2. prometheus reporter panics for an invalid gauge name

  3. This causes the defers on the stack to be called including closer.Close()

  4. scope.Close() tries to acquire the lock again via reportRegistryWithLock

If defer closer.Close() is moved after calling scope.Gauge then the error is reported.

One possible solution is to call gm.Unlock() using defer as well in scope.Gauge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant