Skip to content

Fix concurrent date-time formatting issue in PatternLayout #1485

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

Merged
merged 2 commits into from
May 24, 2023

Conversation

vy
Copy link
Member

@vy vy commented May 23, 2023

Fixes the concurrency issue in DatePatternConverter exhibiting itself under contention and when ThreadLocals are disabled. See @smarkwal's report for details.

@vy vy merged commit 3f5da0a into 2.x May 24, 2023
@vy vy deleted the DatePatternConverter-non-TL-fix branch May 24, 2023 14:33
@vy vy added this to the 2.21.0 milestone May 24, 2023
@vy vy self-assigned this May 24, 2023
@ppkarwasz
Copy link
Contributor

Closes #1490.

theit pushed a commit to theit/logging-log4j2 that referenced this pull request May 30, 2023
@ppkarwasz ppkarwasz modified the milestones: 2.21.0, 2.20.1 Aug 1, 2023
LuciferYang added a commit to apache/spark that referenced this pull request 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 <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
ppkarwasz added a commit that referenced this pull request Jul 4, 2025
This change disables the sharing of formatted timestamps between threads in `InstantPatternThreadLocalCachedFormatter`.

Previously, a mutable `StringBuilder` was shared across threads via a cached object. This could lead to situations where one thread ("owner") was modifying the builder while another thread was reading from it, resulting in inaccurate or truncated timestamps.

This fix ensures that only thread-local instances are used, preventing concurrency issues and improving timestamp correctness under load.

This change is similar in nature to #1485 and fixes #3792.
ppkarwasz added a commit that referenced this pull request Jul 4, 2025
This change disables the sharing of formatted timestamps between threads in `InstantPatternThreadLocalCachedFormatter`.

Previously, a mutable `StringBuilder` was shared across threads via a cached object. This could lead to situations where one thread ("owner") was modifying the builder while another thread was reading from it, resulting in inaccurate or truncated timestamps.

This fix ensures that only thread-local instances are used, preventing concurrency issues and improving timestamp correctness under load.

This change is similar in nature to #1485 and fixes #3792.
ppkarwasz added a commit that referenced this pull request Jul 5, 2025
This change disables the sharing of formatted timestamps between threads in `InstantPatternThreadLocalCachedFormatter`.

Previously, a mutable `StringBuilder` was shared across threads via a cached object. This could lead to situations where one thread ("owner") was modifying the builder while another thread was reading from it, resulting in inaccurate or truncated timestamps.

This fix ensures that only thread-local instances are used, preventing concurrency issues and improving timestamp correctness under load.

This change is similar in nature to #1485 and fixes #3792.
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 this pull request may close these issues.

2 participants