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

GeflUdpAppender throws ClosedChannelException #20

Closed
pfeiler opened this issue Jul 13, 2018 · 13 comments
Closed

GeflUdpAppender throws ClosedChannelException #20

pfeiler opened this issue Jul 13, 2018 · 13 comments
Assignees
Labels

Comments

@pfeiler
Copy link

pfeiler commented Jul 13, 2018

Hi, when logging to Graylog with logback-gelf-1.1.0.jar it stops logging after a minute.
By debugging I see that gelf throws a ClosedChannelException. Maybe gelf needs to check the state of channel and reopen if closed?:

[Ljava.lang.StackTraceElement;@39e25fb8java.nio.channels.ClosedChannelException
	at sun.nio.ch.DatagramChannelImpl.ensureOpen(DatagramChannelImpl.java:320)
	at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:428)
	at de.siegmar.logbackgelf.GelfUdpAppender.appendMessage(GelfUdpAppender.java:81)
	at de.siegmar.logbackgelf.AbstractGelfAppender.append(AbstractGelfAppender.java:106)
	at de.siegmar.logbackgelf.AbstractGelfAppender.append(AbstractGelfAppender.java:28)
	at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:84)
	at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
	at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)
	at ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)
	at ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:414)
	at ch.qos.logback.classic.Logger.info(Logger.java:587)
@osiegmar
Copy link
Owner

From my understanding this can only happen if the DatagramChannel has been closed by the method de.siegmar.logbackgelf.GelfUdpAppender#close as the channel itself is not connected to a remote system. This close method is called by logback when it is stopping (commonly because of shutting down the whole application). Could that be the case in your scenario?

Is the exception thrown all the times after this first minute or does it stop at some point?

Furthermore, the whole stack trace would be interesting. It might contain additional information...

@osiegmar osiegmar self-assigned this Jul 14, 2018
@pfeiler
Copy link
Author

pfeiler commented Jul 14, 2018

Thanks for having a look into this.

  • Exception is thrown with every log statement after channel has closed.
  • The channel closes always at the same log statement, why I don't know.
  • The next entries in the stacktrace are from classes from our application (can't disclose).

I googled a bit, would you please have a look at:
t0xa/gelfj#87 (comment) and t0xa/gelfj@15842b8

@osiegmar
Copy link
Owner

Ok, I need some more time to investigate. I tried to reproduce this by shutting down the graylog server and starting it again, but as expected it did not result in any exception. What operating system and Java version do you use with logback-gelf?

@osiegmar
Copy link
Owner

Cannot reproduce here. Can you try the branch https://github.com/osiegmar/logback-gelf/tree/udp-reopen (version 1.1.1-SNAPSHOT)? I'm testing for isOpen() here and reopen the channel if required.

@etluchs
Copy link

etluchs commented Sep 3, 2018

similar problem here. Only it appears after quite long time (weeks) and only sporadic. Will try the "robust" version ...

@osiegmar
Copy link
Owner

Did the udp-reopen branch solved the issue for someone?

@pfeiler
Copy link
Author

pfeiler commented Sep 28, 2018 via email

@etluchs
Copy link

etluchs commented Sep 29, 2018

Similar here :-( sorry. For the installation in question, we switched to logging to stdout and let docker the forwarding to graylog.
We may still use it for one of the non-docker environments though ...

@osiegmar
Copy link
Owner

Please reopen this ticket if someone can test the branch

@Rustam-Kadyrov
Copy link

Rustam-Kadyrov commented Mar 4, 2019

Had similar problem with version 1.x under docker container. After certain activities GELF appender stopped sending messages to Graylog with exception: java.nio.channels.ClosedChannelException.
Unfortunately I have no chance to check your branch on prod.

@hlzhang
Copy link

hlzhang commented Mar 11, 2019

Had similar problem with version 1.x under docker container. After certain activities GELF appender stopped sending messages to Graylog with exception: java.nio.channels.ClosedChannelException.
Unfortunately I have no chance to check your branch on prod.

+1

@skreuzhuber
Copy link

We had the very same issue and have tested your branch successfully.

We had lost GELF messages after an uptime of about 1-2 days, e.g. no more GELF messages were sent by our applications. In our log files we have encountered the stated ClosedChannelException. We use the GELF Appender within various Spring Boot applications that are deployed as Docker containers and send logs via GELF to Graylog.

This issue was solved by building and including your fix (https://github.com/osiegmar/logback-gelf/tree/udp-reopen). Since about 2 weeks no GELF messages were lost on various environments.

Thanks a lot for your effort. We would kindly appreciate if you merge the fix into the master and include it within one of your next releases. Thanks!

@osiegmar
Copy link
Owner

@skreuzhuber Thanks for your test and for confirming, that the udp-reopen branch fixes the problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants