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

Randomly occuring NPE when logging #822

Open
nadrian4 opened this issue Jun 13, 2024 · 3 comments
Open

Randomly occuring NPE when logging #822

nadrian4 opened this issue Jun 13, 2024 · 3 comments

Comments

@nadrian4
Copy link

Hi, I'm working with Java 17, SLF4j 2.0.12 and logback 1.5.2 and from time to time I randomly get following error when I try to log something:

java.lang.NullPointerException: Cannot invoke "ch.qos.logback.core.Appender.doAppend(Object)" because "appenderArray[i]" is null
        at ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)
        at ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:272)
        at ch.qos.logback.classic.Logger.callAppenders(Logger.java:259)
        at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:426)
        at ch.qos.logback.classic.Logger.filterAndLog_1(Logger.java:402)
        at ch.qos.logback.classic.Logger.info(Logger.java:588)

The configuration file is as below:

<configuration scan="true" scanPeriod="120 seconds">
	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>log/history.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>log/history-%d{MM-dd-yyyy}.log</fileNamePattern>
		</rollingPolicy>
		<encoder>
			<pattern>%date{HH:mm:ss.SSS} %-5level %logger{0} - %msg%n</pattern>
		</encoder>
	</appender>
	<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
		<queueSize>1024</queueSize>
		<neverBlock>true</neverBlock>
		<appender-ref ref="FILE" />
	</appender>
	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%date{HH:mm:ss.SSS} %-5level %logger{0} - %msg%n</pattern>
		</encoder>
	</appender>
	<appender name="stash" class="net.logstash.logback.appender.LogstashUdpSocketAppender">
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
		<host>logstash</host>
		<port>5056</port>
		<layout class="net.logstash.logback.layout.LogstashLayout">
			<customFields>{"userDir":"${user.dir}","hostname":"${HOSTNAME}"}</customFields>
		</layout>
	</appender>
	<root level="INFO">
		<appender-ref ref="stash" />
		<appender-ref ref="ASYNC" />
	</root>
</configuration>

What could be the cause?

@ceki
Copy link
Member

ceki commented Aug 10, 2024

@nadrian4 Can you tell when this issue occurs? Is it during or after reconfiguration? Do you have an idea on the approximate number of threads in your application?

Are the logging threads regular threads or virtual threads? (You are running on JDK 17.)

@ceki
Copy link
Member

ceki commented Aug 12, 2024

@nadrian4 I have tried to reproduce this issue but without success. Does the issue occur if you do not use LogstashUdpSocketAppender? Do you change the logback.xml configuration file often?

Which OS is this? What type of CPU?

@nadrian4
Copy link
Author

Hi @ceki it occurs in non-deterministic conditions even if the reconfiguration is not done at all (e.g. at night when nobody works with these files). The number of threads is aobut 150-200 platform threads.

I have a lot of applications (7000) working with logback and this exception occurs once a week or two. It's really tough to find something that these cases have in common. We worked around this issue by handling the exception, but would be great to find solution.

We didn't try without LogstashUdpSocketAppender, hard to say if it would help. Unfortunately the problem occurs really rarely and we can't switch off Logstash appender, as some part of our system relies on it.

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

No branches or pull requests

2 participants