Skip to content

[Task] Fix thread safety of PendingAckHandleImpl #21304

Closed

Description

@lhotari

PendingAckHandleImpl seems to contain some thread safety issues:
individualAckOfTransaction uses org.apache.commons.collections4.map.LinkedMap which is not thread safe.
Another thread safety issue is the mutation of MutablePair instance. MutablePair is not thread safe.
HashMaps are also used as mutable state.
This state is mutated without a guarantee that the same thread is reading and writing the state or there's some other way to ensure consistency according to the Java Memory Model.

It seems that the intention would be use a single thread execution model to address this. There's a internalPinnedExecutor in
PendingAckHandleImpl which is used to run some operations on the single executor thread.
However, the thread could possibly get switched multiple times in the call chain because of asynchronous method calls.

There's also some code where synchronized blocks are used as a way to ensure consistency such as
synchronized (org.apache.pulsar.broker.transaction.pendingack.impl.PendingAckHandleImpl.this) { and synchronized (PendingAckHandleImpl.this) {.
This is bad since the thread that gets synchronized is whatever thread is completing the asynchronous call. This might for example block threads from the bookkeeper client.

Activity

  1. added
    category/reliability
    on Oct 6, 2023
  2. codelipenghui commented on Oct 7, 2023

    @codelipenghui
    Contributor

    @liangyepianzhou Could you please help take a look at this issue?

  3. github-actions commented on Nov 7, 2023

    @github-actions

    The issue had no activity for 30 days, mark with Stale label.

  4. JooHyukKim commented on Nov 8, 2023

    @JooHyukKim
    Contributor

    If the odds are not high that thread safety issue will happen, maybe no need to be proactive on this, but at least can set up mechanism to easily catch up on this.

  5. lhotari commented on Feb 26, 2024

    @lhotari
    MemberAuthor

    If the odds are not high that thread safety issue will happen, maybe no need to be proactive on this, but at least can set up mechanism to easily catch up on this.

    @JooHyukKim Perhaps in some software that's an acceptable way. Thread safety problems could be extremely rare. Let's say 1 out of 10 million operations fails. That is still a big problem for a messaging system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/transactioncategory/reliability

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions