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

NullPointerException when log4j2 is stoping the GELF appender #111

Closed
badreddine16 opened this Issue Mar 14, 2017 · 2 comments

Comments

2 participants
@badreddine16

badreddine16 commented Mar 14, 2017

logstash-gelf version : 1.11.0

SImple Log4J Appender's Configuration :

<Gelf name="gelf" host="ssl:hostname" port="12201" version="1.1">
	<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY" />
	<Field name="timestamp" pattern="%d{dd MMM yyyy HH:mm:ss,SSS}" />
	<Field name="level" pattern="%level" />
	<Field name="simpleClassName" pattern="%C{1}" />
	<Field name="className" pattern="%C" />
	<Field name="server" pattern="%host" />
	<Field name="server.simple" pattern="%host{simple}" />
	<Field name="server.fqdn" pattern="%host{fqdn}" />
	<Field name="server.addr" pattern="%host{address}" />
</Gelf>

A NullPointerException happens when Log4j close the SSL connection (because he is is trying to stop the appender), but the connection is not established yet.

Stacktrace :

2017-03-14 16:46:25 ERROR SpringApplication:826 - Application startup failed
java.lang.NullPointerException
	at biz.paluch.logging.gelf.intern.sender.GelfTCPSSLSender.closeSocketChannel(GelfTCPSSLSender.java:268) ~[logstash-gelf-1.11.0.jar:?]
	at biz.paluch.logging.gelf.intern.sender.GelfTCPSSLSender.close(GelfTCPSSLSender.java:257) ~[logstash-gelf-1.11.0.jar:?]
	at biz.paluch.logging.gelf.intern.Closer.close(Closer.java:23) ~[logstash-gelf-1.11.0.jar:?]
	at biz.paluch.logging.gelf.log4j2.GelfLogAppender.stop(GelfLogAppender.java:359) ~[logstash-gelf-1.11.0.jar:?]
	at org.apache.logging.log4j.core.config.AbstractConfiguration.stop(AbstractConfiguration.java:272) ~[log4j-core-2.4.1.jar:2.4.1]
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:451) ~[log4j-core-2.4.1.jar:2.4.1]
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:520) ~[log4j-core-2.4.1.jar:2.4.1]
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:536) ~[log4j-core-2.4.1.jar:2.4.1]
	at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.reinitialize(Log4J2LoggingSystem.java:184) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:64) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:49) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:137) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:261) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:232) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:199) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:176) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:315) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
	at xxx.xxx.xxx.Application.main(Application.java:34) [classes/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_112]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_112]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_112]
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.3.0.RELEASE.jar:1.3.0.RELEASE]

@badreddine16 badreddine16 changed the title from NullPointerException when closing SSL connection to NullPointerException when log4j2 is stoping the GELF appender Mar 14, 2017

@mp911de mp911de added the type: bug label Mar 15, 2017

@mp911de

This comment has been minimized.

Owner

mp911de commented Mar 15, 2017

Thanks a lot for your pull-request. If you require an immediate fix, please build the library yourself with your fix applied until the next release of logstash-gelf is available.

@mp911de mp911de added this to the logstash-gelf 1.11.1 milestone Mar 15, 2017

mp911de added a commit that referenced this issue Mar 15, 2017

Guard GelfTCPSSLSender.closeSocketChannel against uninitialized SSLEn…
…gine #111

Do not interact with SSLEngine if SSLEngine is not available. This can happen if the sender is closed without establishing a connection prior closing.

Original pull request: #112.
@mp911de

This comment has been minimized.

Owner

mp911de commented Mar 15, 2017

Fixed via 0125d27.

@mp911de mp911de closed this Mar 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment