Skip to content

Wrap the interruption to a custom exception when a blocking API is interrupted #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

BewareMyPower
Copy link
Contributor

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:

    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.

@BewareMyPower BewareMyPower added the bug Something isn't working label Mar 1, 2023
@BewareMyPower BewareMyPower added this to the 3.1.0 milestone Mar 1, 2023
@BewareMyPower BewareMyPower self-assigned this Mar 1, 2023
@BewareMyPower
Copy link
Contributor Author

It seems to have some bugs, mark it as drafted and I will investigate tomorrow.

@BewareMyPower BewareMyPower marked this pull request as draft March 1, 2023 16:41
…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.
@BewareMyPower BewareMyPower force-pushed the bewaremypower/process-signal branch from 0cfca63 to 1375daf Compare March 2, 2023 05:53
@BewareMyPower BewareMyPower marked this pull request as ready for review March 2, 2023 05:53
@BewareMyPower
Copy link
Contributor Author

@merlimat @RobertIndie @shibd @Demogorgon314 Could anyone take a look?

@RobertIndie
Copy link
Member

Hi, @BewareMyPower I'm reviewing the code. I will give feedback soon.

@BewareMyPower BewareMyPower merged commit ec05f50 into apache:main 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants