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

in_forward: Fixed a problem where connections are not closed on fluentd's shutdown. #861

Closed

Conversation

aiueo4u
Copy link

@aiueo4u aiueo4u commented Mar 18, 2016

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.

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? }
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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?

@repeatedly repeatedly self-assigned this Apr 5, 2016
@tagomoris tagomoris added the pending To be done in the future label Aug 3, 2016
@tagomoris
Copy link
Member

This issue about closing sockets appropriately will be re-checked after porting in_forward into v0.14 APIs and socket/server plugin helpers. Pending.

@tagomoris
Copy link
Member

I created #1401 to solve this problem at v0.14 server plugin helper based code.
Thank you to inform this problem to us!

@tagomoris tagomoris closed this Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending To be done in the future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants