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

Fix goroutine leak #236

Merged
merged 1 commit into from
Sep 12, 2016
Merged

Fix goroutine leak #236

merged 1 commit into from
Sep 12, 2016

Conversation

nghialv
Copy link
Contributor

@nghialv nghialv commented Sep 10, 2016

Hi

I know that http.go will be deprecated in the future.
But i have just found a goroutine leak in this file.

A goroutine leak occurs because the goroutine at line 275 never finish when a panic occurred at line 287 .

So i think we should fix it.

@beorn7
Copy link
Member

beorn7 commented Sep 12, 2016

We cannot "fix" it in that way because it would slow down the HTTP processing, ever for those that do not run into the race condition.

We are really in a dead end with the InstrumentHandler function. I'd like to keep it deliberately broken and deprecated rather than "fixing" it, potentially causing even more surprises and harm.

Sorry for that.

@beorn7 beorn7 closed this Sep 12, 2016
@nghialv
Copy link
Contributor Author

nghialv commented Sep 12, 2016

Hi beorn7. Thanks for your comment.

Can you tell me why "it would slow down the HTTP processing"?

@beorn7
Copy link
Member

beorn7 commented Sep 12, 2016

Because you now are doing the length calculation sequentially after serving the HTTP.

It's really waste of our all time to discuss this further. the function is broken and marked as such. I'd rather invest my time in creating new tooling that is not broken by design.

@nghialv
Copy link
Contributor Author

nghialv commented Sep 12, 2016

No, the length calculation is running in a goroutine. (same as the original version) https://github.com/prometheus/client_golang/pull/236/files#diff-b83b53c6fd7712ee815387960471957bR305

But, I'm looking forward to seeing your new design.
Thanks for your reply.

@beorn7
Copy link
Member

beorn7 commented Sep 12, 2016

OK, I see.

But then the header is still ranged over in a goroutine, so you still have a race if the header map is modified. (I read your added comment as "I also fixed the race condition", but that's actually not the case.)

So if I see correctly, the only change here other than moving code around, is to make the channel buffered so that the goroutine calculating the request size, will finish in any case.

I guess one can do that, it's at least an improvement.

@beorn7 beorn7 reopened this Sep 12, 2016
@beorn7
Copy link
Member

beorn7 commented Sep 12, 2016

Merging as I got nerd-sniped anyway and invested the effort in reviewing this.

@beorn7 beorn7 merged commit 8aae34f into prometheus:master Sep 12, 2016
@nghialv
Copy link
Contributor Author

nghialv commented Sep 12, 2016

Thanks beorn7.

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

Successfully merging this pull request may close these issues.

None yet

2 participants