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

Exceptions are ignored even with ignoreExceptions="false" when booting #1445

Closed
david0 opened this issue Apr 24, 2023 · 3 comments · Fixed by #1549
Closed

Exceptions are ignored even with ignoreExceptions="false" when booting #1445

david0 opened this issue Apr 24, 2023 · 3 comments · Fixed by #1549
Milestone

Comments

@david0
Copy link

david0 commented Apr 24, 2023

Description

We have an rolling file appender with ignoreExceptions="false" and immediateFlush="true" so that in case of any problem with this appender we would expect exceptions.

That works fine for the running application but if the appenders files are not writable during application boot, there are error messages but they are just logged and not thrown. Hence the applications starts "successfully" but with a malfunctioning logging (missing loggers)

I would expect that errors during boot time are thrown if ignoreExceptions is failse

Configuration

Version: 2.19.0

Operating system: Mac OS/X 13.3.1

JDK: OpenJDK Runtime Environment Corretto-17.0.3.6.1 (build 17.0.3+6-LTS)

Logs

2023-04-24 17:34:44,830 main ERROR Unable to create file /tmp/unreadable/error.log java.io.IOException: Permission denied
	at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.base/java.io.File.createNewFile(File.java:1043)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:735)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:718)
	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:144)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:100)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:217)
	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:135)
	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:62)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:61)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:391)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:416)
	at com.github.david0.log4jexceptionsboot.Log4jExceptionsBootApplication.<clinit>(Log4jExceptionsBootApplication.java:11)

2023-04-24 17:34:44,836 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory@53fe15ff] unable to create manager for [/tmp/unreadable/error.log] with data [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData@449a4f23[pattern=/tmp/unreadable/error.%d{yyyy-MM-dd}.%i.log.gz, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[OnStartupTriggeringPolicy, SizeBasedTriggeringPolicy(size=1073741824), TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false)]), strategy=DefaultRolloverStrategy(min=1, max=30, useMax=true), advertiseURI=null, layout=%d %p %C{1.} [%t] %m%n, filePermissions=null, fileOwner=null]] java.lang.IllegalStateException: ManagerFactory [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory@53fe15ff] unable to create manager for [/tmp/unreadable/error.log] with data [org.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData@449a4f23[pattern=/tmp/unreadable/error.%d{yyyy-MM-dd}.%i.log.gz, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[OnStartupTriggeringPolicy, SizeBasedTriggeringPolicy(size=1073741824), TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false)]), strategy=DefaultRolloverStrategy(min=1, max=30, useMax=true), advertiseURI=null, layout=%d %p %C{1.} [%t] %m%n, filePermissions=null, fileOwner=null]]
	at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:146)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:100)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:217)
	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:135)
	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:62)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:61)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:391)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:416)
	at com.github.david0.log4jexceptionsboot.Log4jExceptionsBootApplication.<clinit>(Log4jExceptionsBootApplication.java:11)

2023-04-24 17:34:44,837 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:260)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:136)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:61)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
	at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:391)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:416)
	at com.github.david0.log4jexceptionsboot.Log4jExceptionsBootApplication.<clinit>(Log4jExceptionsBootApplication.java:11)

2023-04-24 17:34:44,838 main ERROR Null object returned for RollingFile in Appenders.
2023-04-24 17:34:44,844 main ERROR Unable to locate appender "errorLogFile" for logger config "root"
17:34:44.861[main] ERROR  c.g.d.l.Log4jExceptionsBootApplication: running

Reproduction

using this:
example.tar.gz

mkdir /tmp/unreadable
chmod 0000 /tmp/unreadable

mvn spring-boot:run
@david0 david0 changed the title Exceptions are ignore even with ignoreExceptions="false" when booting Exceptions are ignored even with ignoreExceptions="false" when booting Apr 25, 2023
@thisdudeiknew
Copy link
Contributor

thisdudeiknew commented Jul 10, 2023

I'm experiencing this bug as well; I believe the fix is around here
Where instead of line 523 being:

return true;

it should be:

return success;

@ppkarwasz
Copy link
Contributor

@david0,

The ignoreExceptions setting works at runtime not configuration time. Adapting it to work at configuration time would be a major refactoring of the code. We might do it in the future.

@thisdudeiknew,

You are right, that method should return success. Can you submit a PR (possibly with a regression test)?

@thisdudeiknew
Copy link
Contributor

@ppkarwasz PR created: #1549.

@vy vy closed this as completed in #1549 Oct 5, 2023
vy pushed a commit that referenced this issue Oct 5, 2023
@vy vy added this to the 2.21.0 milestone Oct 5, 2023
vy pushed a commit that referenced this issue Oct 6, 2023
vy added a commit that referenced this issue Oct 6, 2023
LuciferYang added a commit to apache/spark that referenced this issue Oct 23, 2023
### What changes were proposed in this pull request?
This pr aims upgrade log4j from 2.20.0 to 2.21.0.

### Why are the changes needed?
Support for the zstd compression algorithm has been added in the new version: apache/logging-log4j2#1508 | apache/logging-log4j2#1514
Meanwhile, the new version starts to use Java 11 for building, and the runtime version is still compatible with Java 8: apache/logging-log4j2#1369
The new version also brings some bug fixes, such as:
- Fixed logging of java.sql.Date objects by appending it before Log4J tries to call java.util.Date.toInstant() on it: apache/logging-log4j2#1366
- Fixed concurrent date-time formatting issue in PatternLayout: apache/logging-log4j2#1485
- Fixed buffer size in Log4jFixedFormatter date time formatter: apache/logging-log4j2#1418
- Fixed the propagation of synchronous action failures in RollingFileManager and FileRenameAction: apache/logging-log4j2#1445 | apache/logging-log4j2#1549
- Fixed RollingFileManager to propagate failed synchronous actions correctly: apache/logging-log4j2#1445
and more.

The complete release note is as follows:
- https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.21.0

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #43478 from LuciferYang/SPARK-45625.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
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

Successfully merging a pull request may close this issue.

4 participants