Skip to content

fix: Disable sharing of formatted timestamps between threads#3802

Merged
ppkarwasz merged 1 commit into2.xfrom
fix/2.x/3792_formatted-datetime-sharing
Jul 4, 2025
Merged

fix: Disable sharing of formatted timestamps between threads#3802
ppkarwasz merged 1 commit into2.xfrom
fix/2.x/3792_formatted-datetime-sharing

Conversation

@ppkarwasz
Copy link
Contributor

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.

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 ppkarwasz merged commit 6cd74a8 into 2.x Jul 4, 2025
17 of 18 checks passed
@ppkarwasz ppkarwasz deleted the fix/2.x/3792_formatted-datetime-sharing branch July 4, 2025 12:29
@github-project-automation github-project-automation bot moved this from To triage to Done in Log4j bug tracker Jul 4, 2025
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

Status: Done

Development

Successfully merging this pull request may close these issues.

Broken timestamp since Log4J 2.25

2 participants