-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
in_forward: Fixed a problem where connections are not closed on fluentd's shutdown. #861
Conversation
end | ||
|
||
def listen | ||
log.info "listening fluent socket on #{@bind}:#{@port}" | ||
s = Coolio::TCPServer.new(@bind, @port, Handler, @linger_timeout, log, method(:on_message)) | ||
s = Coolio::TCPServer.new(@bind, @port, Handler, @linger_timeout, log, method(:on_message)) do |connection| | ||
@connections.reject! { |conn| conn.closed? } |
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.
Should this block guard using Mutex?
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 think it doesn't need to be guarded.
(I would like to confirm just in case; does this block
mean do |connection| ... end
, not { |conn| conn.closed? }
, right?)
@connections
is used for closing accepted connections at shutdown, so already closed connections don't need to be included in. I think it is safe that several processes or threads come in this block at the same time.
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.
It looks needed for me too to guard @connections.reject!
using Mutex.
I mean that:
@mutex.synchronize do
@connections.reject!{ |conn| conn.closed? }
@connections << connection
end
Connection callback may run twice immediately if many connection arrived at a time.
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.
Thank you for your comments.
Surely, I think I should guard it by mutex, but please let me ask you a question.
Can this callback be run simultaneously by threads?
It seems that only one thread(@thread
) handles waiting connections, communicating with accepted connections and replying heartbeat request. So only one thread can run this callback at a time, cannot it?
This issue about closing sockets appropriately will be re-checked after porting |
I created #1401 to solve this problem at v0.14 server plugin helper based code. |
At shutdown,
in_forward
plugin doesn't close connections accepted by Coolio::TCPServer, so clients continue to sending requests which main process cannot recognize and are to be lost until the process exits. (I think #801 arises from the same cause as this)I have fixed this problem by keeping accepted connections and closing them at shutdown.