poorbarcode opened a new pull request, #24573:
URL: https://github.com/apache/pulsar/pull/24573

   ### Motivation
   
   **Issue 1**: A deadlock occurs if a call to cancel the pending read is made 
in the callback of reading
   
   Reproduce steps, which are the same as the new test 
`testCancelPendingReadInCheckingNewEntriesCallback`
   
   | thread | read entries | scheduled task that checks new entries |
   | --- | --- | --- |
   | 1 | calls reading entries, but there are no more entries to read |
   | 2 | Cursor added a delayed task named `delayCheckForNewEntriesTask` |
   | 3 | | `delayCheckForNewEntriesTask` runs |
   | 4 | | switch the state to `running` |
   | 5 | close the cursor | 
   | 6 | | falls the callback because the cursor was closed |
   | 8 | | calls `callback` because the cursor was closed, which tries to 
cancel the pending read|
   | 9 | | the cancel pending reading will wait for 
`delayCheckForNewEntriesTask` to be done, but it will never be done, because it 
runs in `delayCheckForNewEntriesTask` |
   
   **Issue 2**: A reading callback may be called twice 
   - `Cursor.checkForNewEntries` will fail the callback if the cursor is closed.
   - `Cursor.checkForNewEntries` will fail the callback at the second time, if 
the callback throws an error
   
   
https://github.com/apache/pulsar/blob/v4.0.5/managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java#L1056-L1109
   
   ```java
       private void checkForNewEntries(OpReadEntry op, ReadEntriesCallback 
callback, Object ctx) {
           try {
               if (isClosed()) {
                   // The first time.
                   callback.readEntriesFailed(new 
CursorAlreadyClosedException("Cursor was already closed"), ctx);
                   return;
               }
           } catch (Throwable t) {
               // the second time
               callback.readEntriesFailed(new ManagedLedgerException(t), ctx);
           }
       }
   ```
   
   
   ### Modifications
   
   
   Fix two issues.
   
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update 
later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: x


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to