-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix NPE in ConfigurationScheduler by ensuring scheduledFuture is chec… #4118
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
Open
ramanathan1504
wants to merge
29
commits into
apache:2.x
Choose a base branch
from
ramanathan1504:Fixes-NPE-in-ConfigurationScheduler
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−5
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
2df0b46
Fix NPE in ConfigurationScheduler by ensuring scheduledFuture is chec…
ramanathan1504 50690c6
Restrict JUnit dependencies to below version 6.x to maintain compatib…
ramanathan1504 bc3e896
Don't override `apache-rat-plugin` version (#4123)
ppkarwasz 3be9e4c
Bump actions/stale from 9.1.0 to 10.2.0 in the dependencies group acr…
dependabot[bot] 2582986
Fix KafkaAppender reporting error after successful retry (#4125)
SebTardif 0edc9c2
Revamped `ListAppender` for thread-safety (#4111)
ramanathan1504 ed78b98
Improve `CronExpression` tests to cover daylight saving and schedulin…
ramanathan1504 ba36fe6
Fix `createOnDemand` for Rolling File Appender (#4072)
ramanathan1504 e8c23fe
Add support for max compression delay in compression actions (#4071)
ramanathan1504 7fe84f9
Improve logging for `LinkageError` scenarios involving the LMAX Disru…
ramanathan1504 ba691e0
Fix changelog issue and PR references for Disruptor initialization er…
ramanathan1504 b02c79d
Fix encoding of `MSGID` and `SD-ID` fields of `StructuredDataMessage`…
vy fe38807
Fix stack trace rendering for exceptions with identity malfunction (#…
ramanathan1504 f298ff1
Remove the `patternFlags` attribute from `RegexFilter` (#4119)
ramanathan1504 3784f08
Fix `DatePatternConverter` locale parsing when timezone is omitted (#…
ramanathan1504 2ca444b
Harden `readObject(ObjectInputStream)` method argument checks (#4098)
SunWeb3Sec fcb6e4e
Fix resource leaks in `ConfigurationSource` when loading via URL (#4127)
SebTardif 4f79ad0
Adopt the Dependabot changelog 'draft trick' (#4148)
ppkarwasz 34bc8cc
Add Dependabot config for the 2.26.x maintenance branch (#4149)
ppkarwasz c7103d5
Fix handling of non-finite numbers while encoding `MapMessage` to JSO…
vy 70d3313
Remove `/log4j-slf4j-impl` Dependabot execution (#4151)
ppkarwasz 16ce65b
Upgrade Maven and Maven Wrapper versions to `3.9.16` and `3.3.4`, res…
vy c8efe4b
Adds `maxRandomDelay` configure to Rolling Appenders (#4165)
vy ab98fd5
Merge `2.26.1` to `2.x` (#4169)
ramanathan1504 9aaf074
Add `2.25.5` release notes (#4174)
ramanathan1504 1f9a514
Add native tracing fields to LogEvent to eliminate async MDC overhead…
ramanathan1504 31b0e2d
Fix NPE in ConfigurationScheduler by ensuring proper reset of schedul…
ramanathan1504 fb8abe6
Fix NPE in ConfigurationScheduler for frequent cron schedules
ramanathan1504 6d93d44
Merge branch '2.x' into Fixes-NPE-in-ConfigurationScheduler
ramanathan1504 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...e-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationSchedulerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.logging.log4j.core.config; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.ScheduledFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import org.apache.logging.log4j.core.util.CronExpression; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ConfigurationSchedulerTest { | ||
|
|
||
| @Test | ||
| void testScheduleWithCronRaceCondition() throws Exception { | ||
| final CountDownLatch firstRunLatch = new CountDownLatch(1); | ||
| final CountDownLatch secondRunLatch = new CountDownLatch(1); | ||
|
|
||
| final Runnable command = () -> { | ||
| if (firstRunLatch.getCount() > 0) { | ||
| firstRunLatch.countDown(); | ||
| } else { | ||
| secondRunLatch.countDown(); | ||
| } | ||
| }; | ||
|
|
||
| final ConfigurationScheduler scheduler = new ConfigurationScheduler() { | ||
| private final AtomicBoolean first = new AtomicBoolean(true); | ||
|
|
||
| @Override | ||
| public ScheduledFuture<?> schedule(final Runnable cmd, final long delay, final TimeUnit unit) { | ||
| if (first.compareAndSet(true, false)) { | ||
| final ScheduledFuture<?> future = super.schedule(cmd, 0, TimeUnit.MILLISECONDS); | ||
| try { | ||
| assertTrue(firstRunLatch.await(5, TimeUnit.SECONDS), "First run failed, likely NPE"); | ||
|
|
||
| Thread.sleep(100); | ||
| } catch (final InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| return future; | ||
| } | ||
| return super.schedule(cmd, delay, unit); | ||
| } | ||
| }; | ||
|
|
||
| try { | ||
| scheduler.incrementScheduledItems(); | ||
| scheduler.start(); | ||
|
|
||
| final CronExpression cron = new CronExpression("0/1 * * * * ?"); | ||
|
|
||
| final ScheduledFuture<?> future = scheduler.scheduleWithCron(cron, new Date(), command); | ||
|
|
||
| future.cancel(false); | ||
|
|
||
| assertFalse( | ||
| secondRunLatch.await(2, TimeUnit.SECONDS), | ||
| "Task ran after cancellation. Monotonic reset is broken."); | ||
|
|
||
| } finally { | ||
| scheduler.stop(1, TimeUnit.SECONDS); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/changelog/.2.x.x/2073_fix_ConfigurationScheduler_NPE.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <entry xmlns="https://logging.apache.org/xml/ns" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation=" | ||
| https://logging.apache.org/xml/ns | ||
| https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" | ||
| type="fixed"> | ||
| <issue id="2073" link="https://github.com/apache/logging-log4j2/issues/2073"/> | ||
| <issue id="4118" link="https://github.com/apache/logging-log4j2/pull/4118"/> | ||
| <description format="asciidoc"> | ||
| Fix `NullPointerException` in `ConfigurationScheduler` for a frequently executing cron schedule. | ||
| </description> | ||
| </entry> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramanathan1504, test passes without your changes. Could you make sure this test fails without the fix?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vy , I restored the file log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java. After doing so, the build succeeded—the test case passes perfectly without requiring any modifications to the source file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test still passes without the fix, so it does not prove the race is fixed. Also, the current placeholder approach can still leave the returned
CronScheduledFuturepointing at the already-fired first future if the task runs beforescheduleWithCron()callsreset().Please make the returned future update monotonic. If the first execution already advanced it to the next scheduled run, the initial
reset()must not overwrite it with the stale first future.Could implement the following changes, please?
2.xfinallyblock in the test;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vy 31b0e2d