You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "JooHyukKim (via GitHub)" <gi...@apache.org> on 2023/05/06 05:08:35 UTC

[GitHub] [pulsar] JooHyukKim opened a new pull request, #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

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

   Fixes #19671
   
   ### Motivation
   
   To resolve the thread-safety issue around Java client's seek logic identified by apache/pulsar#19671.
   
   ### Modifications
   
   - Made ConsumerImpl immediately cancel future and return if `duringSeek` flag is not false.
   
   ### 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)*.
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### 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: https://github.com/JooHyukKim/pulsar/pull/1


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186875184


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   > completing with `null` will not set the message clear.
   
   That indeed the operation is "cancelled".



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186971096


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   After a closer look `f.cancel(true)` is the same as `f.completeExceptionally(new CancellationException())`. So either way should be OK.



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186831548


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   Also, this is a local future, that I believe you can complete it properly (@michaeljmarshall shall we complete with `null` or exception here?) instead of call `cancel`.



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537453814

   > @JooHyukKim BTW, edit comment won't send notification, I suggest you create new comment when you'd like to notify reviewers.
   
   Right, thank you for the reminder 👍🏻


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] Technoboy- commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1547101579

   @tisonkun 
   For this patch, maybe you forget to set the milestone. and there are some modifications not related to the issue


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1539967517

   > Thanks for your contribution @JooHyukKim! Would you mind updating the Javadoc for the `seek` and `seekAsync` methods to indicate what will happen if a user calls a seek method before a previous call completes?
   
   Will do! 🙏🏽 Later after work 😀


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537265913

   > Could you add a test for your changes?
   
   Sure! Will do in bit.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538222368

   > @JooHyukKim May I ask what `#1` means?
   
   Oh... 😅 "#1" means My first ever contribution to Pulsar! 
   
   I can remove the "#1" part from title if you think it will confuse the maintenance team. Just let me know~  🙏🏼 @tisonkun 
   
   > Thanks for your contribution!
   
   @tisonkun Thank you for great guidance on your part 🙏🏼


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537476267

   > I'd appreciate it if you can provide a timing diagram to prove the fix. You may refer to [apache/curator#430](https://github.com/apache/curator/pull/430) as a typical description.
   
   Np 👍🏻.  May I ask what tool everyone conventionally uses? Or your suggestion @tisonkun ?


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537964007

   > But any tool you searched is acceptable as long as the diagram is clear (with text, reviewers manually dump to diagram).
   
   Thank you for the tips! 


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] nodece commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186861259


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   Good catch! I prefer  `seekFuture.completeExceptionally()` instead of `cancel(true);`.
   
   Or we can use a global future instead local future, see https://github.com/apache/pulsar/pull/18202.
   
   
    



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538024654

   > personal fork is not running CI
   
   Yes.
   
   You may take https://github.com/lhotari/pulsar/pull/145 as an example. IIRC GitHub sometimes stuck on turning on Actions..I don't have too much suggestions here but I can follow the instructions in Actions tab to add a sample workflow and then GitHub turn on Actions.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] codecov-commenter commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538216007

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/20242?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#20242](https://app.codecov.io/gh/apache/pulsar/pull/20242?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (4075a39) into [master](https://app.codecov.io/gh/apache/pulsar/commit/98413642995eb6e562f6a591dcf56e20ac0cc7ef?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (9841364) will **decrease** coverage by `0.02%`.
   > The diff coverage is `51.42%`.
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/20242/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://app.codecov.io/gh/apache/pulsar/pull/20242?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #20242      +/-   ##
   ============================================
   - Coverage     72.87%   72.86%   -0.02%     
   + Complexity    31943     3601   -28342     
   ============================================
     Files          1868     1868              
     Lines        138594   138597       +3     
     Branches      15246    15247       +1     
   ============================================
   - Hits         101003   100991      -12     
   - Misses        29547    29557      +10     
   - Partials       8044     8049       +5     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | inttests | `24.21% <22.85%> (-0.05%)` | :arrow_down: |
   | systests | `24.78% <20.00%> (-0.15%)` | :arrow_down: |
   | unittests | `72.18% <51.42%> (+0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://app.codecov.io/gh/apache/pulsar/pull/20242?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...va/org/apache/pulsar/client/impl/ConsumerImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/20242?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL0NvbnN1bWVySW1wbC5qYXZh) | `76.40% <51.42%> (-0.03%)` | :arrow_down: |
   
   ... and [64 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/20242/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186877917


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   Sounds reasonable with your test case. I'll give another look tomorrow.



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537414031

   I'd appreciate it if you can provide a timing diagram to prove the fix. You may refer to https://github.com/apache/curator/pull/430 as a typical description.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537410814

   @JooHyukKim BTW, edit comment won't send notification, I suggest you create new comment when you'd like to notify reviewers.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186864159


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   > Also, this is a local future, that I believe you can complete it properly (@michaeljmarshall shall we complete with null or exception here?) instead of call cancel.
   
   By refering to  @michaeljmarshall mentions in [his original issue](https://github.com/apache/pulsar/issues/19671#:~:text=I%20expect%20the%20client%20to%20either%20cancel%20the%20first%20operation%20or%20to%20fail%20the%20second%20operation%20due%20to%20an%20illegal%20call.), I agree that completing with `null` makes more sense?



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538020452

   Thank you @tisonkun, I made below two check style commands pass, "locally".
   
   My personal fork is not running CI. Is it supposed to run though? 🤔🤔
   
   > ```
   > mvn -B -T 8 -ntp initialize apache-rat:check license:check
   > mvn -B -T 8 -ntp initialize checkstyle:check
   > ```
   > 
   > Ping me once CI passed in your personal fork.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538217675

   Merging...
   
   Thanks for your contribution!


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538237232

   Never mind. I can edit the commit message before merging :D


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537479452

   > tool
   
   Generally, I just write in text :D
   
   It's about:
   
   1. Define the actors.
   2. Describe at T_N, what actor takes what action
   3. The order of T_N
   4. What actions cause race condition
   
   But any tool you searched is acceptable as long as the diagram is clear (with text, reviewers manually dump to diagram).


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538013120

   /pulsarbot rerun-failure-checks


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538137187

   /pulsarbot rerun-failure-checks


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1538218263

   @JooHyukKim May I ask what `#1` means? It looks to me as part one or first attempt that I may wonder if you have outstanding works on this topic.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1547105417

   @Technoboy- Thanks for setting up the milestone.
   
   > not related to the issue
   
   Yep. I'm investigating some tools to unify whitespace so that we don't ask for aligning again and again.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] nodece commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537453459

   How to verify your changes?
   
   You can set `true` for the `duringSeek` flag, and then call the seek method, you got a canceled future.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] nodece commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537165105

   Could you add a test for your changes?


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] JooHyukKim commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "JooHyukKim (via GitHub)" <gi...@apache.org>.
JooHyukKim commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1186873025


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   But then again, completing with `null` will not set the message clear. I think we should just cancel the `seekFuture`. 



-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun merged pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun merged PR #20242:
URL: https://github.com/apache/pulsar/pull/20242


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] tisonkun commented on pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#issuecomment-1537969620

   @JooHyukKim Please fix style violation by yourself. You can use CI workflow in your personal fork to verify. Or the command should be:
   
   ```
   mvn -B -T 8 -ntp initialize apache-rat:check license:check
   mvn -B -T 8 -ntp initialize checkstyle:check
   ```
   
   Ping me once CI passed in your personal fork.


-- 
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-unsubscribe@pulsar.apache.org

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


[GitHub] [pulsar] michaeljmarshall commented on a diff in pull request #20242: [fix][client] Java Client's Seek Logic Not Threadsafe #1

Posted by "michaeljmarshall (via GitHub)" <gi...@apache.org>.
michaeljmarshall commented on code in PR #20242:
URL: https://github.com/apache/pulsar/pull/20242#discussion_r1188120436


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2153,9 +2153,14 @@ private CompletableFuture<Void> seekAsyncInternal(long requestId, ByteBuf seek,
 
         MessageIdAdv originSeekMessageId = seekMessageId;
         seekMessageId = (MessageIdAdv) seekId;
-        duringSeek.set(true);
+        
+        if (!duringSeek.compareAndSet(false, true)) {
+            log.warn("[{}][{}] Attempting to seek operation that is already in progress, cancelling {}", 
+                    topic, subscription, seekBy);
+            seekFuture.cancel(true);

Review Comment:
   Nit: I think an `IllegalStateException` would be a clearer exception indicating to the user that it was not a valid time to call this method. One problem with `CancellationException` is that it has no message. However, I see that there is a warning log indicating the problem, so it might be fine.



-- 
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-unsubscribe@pulsar.apache.org

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