-
Notifications
You must be signed in to change notification settings - Fork 33
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
Improve broker initiated client disconnects #816
Improve broker initiated client disconnects #816
Conversation
cffea6d
to
f8a0fca
Compare
One thing we don't get now is the "async" close of ALL connections on shutdown. If there are multiple "zombies" on shutdown we'll have to wait |
Yes, but im thinking we can have that logic elsewhere, like push all connections to a Channel and then let a (limited) amount of fibers to work it off until it's empty. |
57efbec
to
7961ff6
Compare
Client#close
to force close socket
Updated the title and description. I've added the solution with fibers and a channel to disconnects clients "async" on shutdown. |
src/lavinmq/vhost.cr
Outdated
else | ||
fiber_id = fiber_count &+= 1 | ||
@log.trace { "spawning close conn fiber #{fiber_id} " } | ||
wg.spawn do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make a PR to the stdlib so that we can name fibers spawned by WaitGroup#spawn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR sent.
src/lavinmq/vhost.cr
Outdated
end | ||
@log.trace { "exiting close conn fiber #{fiber_id} " } | ||
end | ||
Fiber.yield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required? Doesn't Channel#send
on a unbuffered channel automatically yield the current fiber?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why, but it did spawn one extra fiber. Not a big deal, but...
WHAT is this pull request doing?
Writing to client sockets may block a fiber because the buffers are full. When this happens this fiber will hold the write lock in
Client
until it manage to write the data. Because if this it's not possible to force close a connection from the management UI, and the http request will timeout. It will also affect lavinmq shutdown becauseVHost#close
will be blocked from closing all connections effectively.This PR will:
#close
that will set awrite_timeout
on the socket.HOW can this pull request be tested?
Manually with a "bad" client, e.g. unlimited prefetch and no acking. Let it consume until LavinMQ stops because of tcp back pressue. Try kill the connection.