Skip to content

Conversation

@drghdtjr
Copy link

In Pekko HTTP’s asynchronous execution model, multiple threads may access the same PekkoRouteHolder instance concurrently.
The class previously relied on a non-thread-safe StringBuilder and mutable fields without synchronization, which allowed concurrent route-matching operations to corrupt internal state.

Changes

Added synchronized to all methods that mutate internal state in PekkoRouteHolder.

Ensured that route path updates and unmatched path state updates occur atomically.

Technical Rationale (Alternatives Considered)

  • StringBuffer
    StringBuffer synchronizes individual method calls, but it does not guarantee atomicity across multiple dependent state updates. Since the route path and unmatched path must be updated together to maintain consistency, this approach was insufficient to fully resolve the race condition.

  • Immutable String
    Using immutable String objects was also considered. However, frequent string concatenation during Pekko route matching would result in excessive object creation and increased GC pressure, negatively impacting performance.

  • synchronized methods (chosen approach)
    Synchronizing state-modifying methods ensures consistency across related fields with minimal structural changes. Given that route matching is not a hot path with heavy contention, the performance impact is negligible while fully addressing the race condition.

issue : #15681

@drghdtjr drghdtjr requested a review from a team as a code owner January 12, 2026 10:20
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.

1 participant