Skip to content

[Bug] TopicTransactionBuffer contains potential thread safety issues #22119

Closed

Description

@lhotari

Search before asking

  • I searched in the issues and found nothing similar.

Version

master

Minimal reproduce step

The ongoingTxns field is a LinkedMap which isn't thread safe.

What did you expect to see?

thread safe handling in TopicTransactionBuffer

What did you see instead?

ongoingTxns is handled in a problematic way. There are multiple threads that both mutate and read the collection.
It's possible that this isn't a problem, but it's very hard to reason about the thread safetyness of the code currently.

There definitely have been attempts to ensure thread safety. There seems to be an assumption that it's fine to either have synchronized (TopicTransactionBuffer.this) { or run on a single thread such as
topic.getBrokerService().getPulsar().getTransactionExecutorProvider().getExecutor(this), to make it thread safe.

One note about topic.getBrokerService().getPulsar().getTransactionExecutorProvider().getExecutor(this) is that this is pointing to different object instances in the code base. It wouldn't be ensuring single threaded access to all accesses of the object instances that are handled.

It is possible that thread safety is achieved through ways that are hard to observe. As long as all accesses form a "happens-before" chain, even through "piggy backing", it's possible that the code is after all thread safe. The problem is that a small change might break that and the solution is very brittle. Thread safety issues are very hard to notice. The best way to prevent them is to write code that is thread safe.

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. self-assigned this
    on Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions