-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ def start | |
|
||
@lsock = listen | ||
@loop.attach(@lsock) | ||
@connections = [] | ||
|
||
@usock = SocketUtil.create_udp_socket(@bind) | ||
@usock.bind(@bind, @port) | ||
|
@@ -82,11 +83,15 @@ def shutdown | |
@usock.close | ||
@thread.join | ||
@lsock.close | ||
@connections.each { |c| c.close } | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I think it doesn't need to be guarded.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks needed for me too to guard @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 commentThe 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. |
||
@connections << connection | ||
end | ||
s.listen(@backlog) unless @backlog.nil? | ||
s | ||
end | ||
|
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.
By the way, I have another question about
#shutdown
. Should watchers be detached after{@usock,@lsock}.close
in#shutdown
? Otherwise, requests sent from clients between@loop.watchers.each { |w| w.detach if w.attached? }
and@lsock.close
would be lost.