-
Notifications
You must be signed in to change notification settings - Fork 220
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
Memory leak using OnBasicAuthWrapper Hook #177
Comments
Hi, I digged deeper into the problem and it seems that there is a memory leak when the username / password is incorrect. From what I have seen, there are two goroutines that never end:
When such error occurs, the goroutine I tried to call manually to if client.err != nil {
client.Close()
return
} But then the this goroutine go func() { //write
client.writeLoop()
client.wg.Done()
}() gets blocked in From what I understand, the Can somebody give some light on this problem? Thank you very much! Xavi |
Hi, It seems I got it fixed, adding this piece of code if client.err != nil {
client.Close()
close(client.close)
} just before I will deploy it in production and create a pull request, but it would be nice to get the opinion of the maintainer. Thanks! Xavi |
Opened a pull request: #178 |
Oh, that is an impressive deep dive. I can reproduce your problem and you are right. Give me some time, I am looking into it. |
@xorduna After some digging, I think the root cause is that the server does not close the underlying TCP connection when the client gives an invalid username/password, or lets say, under any authentication failed situations.
Line 1473 in 52e1cba
When clients providing invalid username/password:
This two gorouting will be released when the underlying TCP connection get closed. So I think this PR #178 may not solve the problem. I think always close the underlying TCP connection would be the solution, like this:
But sorry I don't have much time to test it carefully, would you please verify this and raise another PR if it works? Many thanks! |
HI @DrmagicE Thanks for answering! I tried your fix, but when executing What about executing Thanks! Xavi |
fix #177 Co-authored-by: 张力方 <[email protected]>
@xorduna Hi, sorry for the late reply. I have submitted a pr which should fix the problem.
|
Hi,
We are currently experiencing a memory leak using gmqtt. The broker has around 20 clients that are publishing messages and no one is consuming. We are inserting data in the database using the OnMsgArrived hook and authenticating clients using OnBasicAuthWrapper hook.
After some further investigation I found the problem is on the OnBasicAuthWrapper hook. Apparently when there an in valid password, this error is thrown:
If we check the code on
client.go
, methodserve()
and follow the execution with the debugger, we see that after sending the "error authentication problem" the goroutine callsclient.wg.Wait()
. That cause the routing to stay in wait status and never end.Is this a normal behaviour?
I followed the code in
https://github.com/DrmagicE/gmqtt/blob/master/plugin/auth/hooks.go
is something wrong with my code?This is the plugin load function
And that is the OnBasicAuthHook hook
I enabled pprof on the broker and I from what i see there are thousands of goroutines blocked and waiting ... Is that normal?
goroutine-stack.txt
Here can see also the space_inuse from the heap
Thank you very much!
Xavi
The text was updated successfully, but these errors were encountered: