Skip to content

Conversation

@Denovo1998
Copy link
Contributor

@Denovo1998 Denovo1998 commented Aug 12, 2025

Fixes #24578

Main Issue: #xyz

PIP: #xyz

Motivation

Fixed race conditions in thread safety tests that were causing intermittent IllegalReferenceCountException failures due to improper resource cleanup order and unrealistic concurrent write patterns.

Modifications

  1. Enhanced Thread Safety Test Design
  • Fixed concurrent write race condition: Changed testConcurrentContainsMessageWithWrites from concurrent writes to sequential writes with concurrent reads, matching real-world
    usage patterns where addMessage is called sequentially
  • Improved test structure: Single writer thread generates sequential ledgerIds (1000, 1001, 1002...) while multiple reader threads concurrently call containsMessage()
  • Added proper error handling: Enhanced exception tracking and reporting with detailed logging
  1. Fixed Resource Cleanup Race Condition
  • Resolved IllegalReferenceCountException: Fixed tearDown method to shutdown ExecutorService before closing tracker, preventing threads from accessing released Netty ByteBufs
  • Improved cleanup order: Ensures all background threads are terminated before releasing resources

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: Denovo1998#9

@github-actions
Copy link

@Denovo1998 Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@lhotari
Copy link
Member

lhotari commented Aug 14, 2025

  • Fixed concurrent write race condition: Changed testConcurrentContainsMessageWithWrites from concurrent writes to sequential writes with concurrent reads, matching real-world
    usage patterns where addMessage is called sequentially

Is single threaded usage guaranteed within Pulsar? IIRC, there might be one thread performing an operation at a time, but Pulsar dispatchers execute on different threads depending on the scenario.
This could be simulated in a test where there's a thread pool of multiple threads, but the task would be executed on different thread each time.

@lhotari
Copy link
Member

lhotari commented Aug 14, 2025

@Apurva007 Please review

@Denovo1998
Copy link
Contributor Author

May be addressed in #24739 .

@Denovo1998 Denovo1998 closed this Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failure in branch-3.0 and branch-3.0: BucketDelayedDeliveryTrackerThreadSafetyTest.testConcurrentContainsMessageWithWrites

2 participants