apache / pulsar-client-python

Apache Pulsar Python client library
https://pulsar.apache.org/
Apache License 2.0
51 stars 40 forks source link

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

Closed BewareMyPower closed 1 year ago

BewareMyPower commented 1 year ago

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

BewareMyPower commented 1 year ago

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

BewareMyPower commented 1 year ago

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

RobertIndie commented 1 year ago

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