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

Concurrent calls to DefaultTracer results in 2 tracers existing with one being inactive #1247

Closed
LordRalex opened this issue May 19, 2022 · 1 comment · Fixed by #1248
Closed
Assignees
Labels

Comments

@LordRalex
Copy link

Describe the bug
When 2 goroutines run at the same time at start-up and both call the apm.DefaultTracer call, then a race-condition occurs where both calls attempt to create a new Tracer. In this scenario, one tracer loses out and disables itself while the other tracer continues to work.

I encountered this during a start-up scheduled task and creation of a gin handler. The gin tracer was being marked as inactive while the scheduled process continues.

There is a read-lock on the tracer. However, this is only when it is read, and is a very short lock. When the first caller runs, it gets null and releases the lock. While the first caller is creating the new tracer, the second caller runs this method, and passes through the lock, also seeing null. This caller then creates a new tracer. When SetDefaultTracer is called after it creates it, it will terminate the tracer that the first caller generated and made default.

To Reproduce
Steps to reproduce the behavior:
Following code:

go func() {
  web := gin.New()
  web.Use(apmgin.Middleware(web))
}

go func() {
  trans := apm.DefaultTracer().StartTransaction("gameCacheSync", "schedule")
  defer trans.End()
}

Expected behavior
Single tracker exists, which sends transactions from both Gin and scheduled process.

@LordRalex LordRalex changed the title Concurrent calls to DefaultTracer results in 2 tracers existing Concurrent calls to DefaultTracer results in 2 tracers existing with one being inactive May 19, 2022
@axw
Copy link
Member

axw commented May 20, 2022

Thanks for the report @LordRalex! We'll get that fixed shortly.

@axw axw self-assigned this May 20, 2022
@axw axw closed this as completed in #1248 May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants