Fix: don't set interrupt flag again after catching interrupt exception in Pulsar Client #5643
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, if the a consumer gets interrupted will waiting on receive(), the interrupt exception just wrapped in a PulsarClientException and the thread is interrupted again. Setting the interrupt flag again for this thread is unnecessary as we already throw an exception and it can also unfavorable behavior. For example in the following code, if I have a thread...
The thread has a while loop that calls consumer receive(). If the thread gets interrupted, I would like to break from the while loop and close the consumer and client. However, closing the client and consumer cannot happen successfully because we set the interrupt flag for this thread after catching an interrupt exception causing any subsequent code e.g. close() to be interrupted as well which is not an ideal behavior.
This also causes non-ideal behavior in the pulsar-flink source as the above situation happens when a Flink job with a Pulsar source gets terminated.
Modifications
remove Thread.currentThread().interrupt();