Wrap the interruption to a custom exception when a blocking API is interrupted#99
Merged
BewareMyPower merged 1 commit intoapache:mainfrom Mar 7, 2023
Conversation
Contributor
Author
|
It seems to have some bugs, mark it as drafted and I will investigate tomorrow. |
…terrupted ### Motivation Currently, when a blocking API is interrupted by a signal, `SystemError` will be thrown. However, in this case, `PyErr_SetInterrupt` will be called and next time a blocking API is called, `std::system_error` will be somehow thrown. The failure of https://lists.apache.org/thread/cmzykd9qz9x1d0s35nc5912o3slwpxpv is caused by this issue. The `SystemError` is not called, then `client.close()` will be skipped, which leads to the `bad_weak_ptr` error. P.S. Currently we have to call `client.close()` on a `Client` instance, otherwise, the `bad_weak_ptr` will be thrown. However, even if we caught the `SystemError` like: ```python try: msg = consumer.receive() # ... except SystemError: break ``` we would still see the following error: ``` terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted Aborted ``` ### Modifications - Wrap `ResultInterrupted` into the `pulsar.Interrupted` exception. - Refactor the `waitForAsyncValue` and `waitForAsyncResult` functions and raise `pulsar.Interrupted` when `PyErr_CheckSignals` detects a signal. - Add `InterruptedTest` to cover this case. - Remove `future.h` since we now use `std::future` instead of the manually implemented `Future`. - Fix the `examples/consumer.py` to support stopping by Ctrl+C.
0cfca63 to
1375daf
Compare
Contributor
Author
|
@merlimat @RobertIndie @shibd @Demogorgon314 Could anyone take a look? |
shibd
approved these changes
Mar 7, 2023
Member
|
Hi, @BewareMyPower I'm reviewing the code. I will give feedback soon. |
RobertIndie
approved these changes
Mar 7, 2023
BewareMyPower
added a commit
that referenced
this pull request
Mar 8, 2023
…terrupted (#99) ### Motivation Currently, when a blocking API is interrupted by a signal, `SystemError` will be thrown. However, in this case, `PyErr_SetInterrupt` will be called and next time a blocking API is called, `std::system_error` will be somehow thrown. The failure of https://lists.apache.org/thread/cmzykd9qz9x1d0s35nc5912o3slwpxpv is caused by this issue. The `SystemError` is not called, then `client.close()` will be skipped, which leads to the `bad_weak_ptr` error. P.S. Currently we have to call `client.close()` on a `Client` instance, otherwise, the `bad_weak_ptr` will be thrown. However, even if we caught the `SystemError` like: ```python try: msg = consumer.receive() # ... except SystemError: break ``` we would still see the following error: ``` terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted Aborted ``` ### Modifications - Wrap `ResultInterrupted` into the `pulsar.Interrupted` exception. - Refactor the `waitForAsyncValue` and `waitForAsyncResult` functions and raise `pulsar.Interrupted` when `PyErr_CheckSignals` detects a signal. - Add `InterruptedTest` to cover this case. - Remove `future.h` since we now use `std::future` instead of the manually implemented `Future`. - Fix the `examples/consumer.py` to support stopping by Ctrl+C. (cherry picked from commit ec05f50)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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, when a blocking API is interrupted by a signal,
SystemErrorwill be thrown. However, in this case,PyErr_SetInterruptwill be called and next time a blocking API is called,std::system_errorwill be somehow thrown.The failure of
https://lists.apache.org/thread/cmzykd9qz9x1d0s35nc5912o3slwpxpv is caused by this issue. The
SystemErroris not called, thenclient.close()will be skipped, which leads to thebad_weak_ptrerror.P.S. Currently we have to call
client.close()on aClientinstance, otherwise, thebad_weak_ptrwill be thrown.However, even if we caught the
SystemErrorlike:we would still see the following error:
Modifications
ResultInterruptedinto thepulsar.Interruptedexception.waitForAsyncValueandwaitForAsyncResultfunctions and raisepulsar.InterruptedwhenPyErr_CheckSignalsdetects a signal.InterruptedTestto cover this case.future.hsince we now usestd::futureinstead of the manually implementedFuture.examples/consumer.pyto support stopping by Ctrl+C.