Skip to content

[fix] Handle exceptions when creating timers when fd limit is reached - #203

Merged
shibd merged 3 commits into
apache:mainfrom
BewareMyPower:bewaremypower/cnx-exception
Mar 2, 2023
Merged

shibd merged 3 commits into
apache:mainfrom
BewareMyPower:bewaremypower/cnx-exception

Conversation

@BewareMyPower

Copy link
Copy Markdown
Contributor

Fixes #202

Motivation

When a deadline_timer is constructed, boost::system::system_error would be thrown if the fd limit is reached. In this case, the following APIs would fail with exception instead of returning a Result:

  • createProducer
  • subscribe
  • createReader

P.S. This behavior is not documented in Boost's documents.

Generally, we should not allow exceptions being thrown from those APIs because we return a Result to indicate the error. In addition, these exceptions cannot be caught by the wrapper of other languages.

There is a similar issue: apache/pulsar#14582. However, apache/pulsar#14587 only fixes the case when creating a socket. The exception from the constructor of deadline_timer is not processed.

Modifications

Handle the exceptions when creating a socket or timer from ExecutorService to restart this executor, then propagate a std::runtime_error. Don't allow creating a timer directly from io_service so that exceptions can be handled well.

In addition, catch the runtime_error when:

  • Creating a producer (ProducerImpl and PartitionedProducerImpl)
  • Creating a consumer (ConsumerImpl and MultiTopicsConsumerImpl)
  • Creating a reader (ReaderImpl)

because the constructors of them all create at least one timer.

Verifications

Add tests/unix/ConnectionFailTest.cc for Unix systems because setrlimit is a POSIX API. It covers the cases when the fd limit is not enough to create a producer, a consumer and a reader.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

@BewareMyPower BewareMyPower added the bug Something isn't working label Feb 21, 2023
@BewareMyPower BewareMyPower added this to the 3.2.0 milestone Feb 21, 2023
@BewareMyPower BewareMyPower self-assigned this Feb 21, 2023
@BewareMyPower
BewareMyPower force-pushed the bewaremypower/cnx-exception branch from 5e1ea72 to 6ed4c9c Compare February 21, 2023 08:16
Fixes apache#202

### Motivation

When a `deadline_timer` is constructed, `boost::system::system_error`
would be thrown if the fd limit is reached. In this case, the following
APIs would fail with exception instead of returning a `Result`:
- `createProducer`
- `subscribe`
- `createReader`

P.S. This behavior is not documented in Boost's documents.

Generally, we should not allow exceptions being thrown from those APIs
because we return a `Result` to indicate the error. In addition, these
exceptions cannot be caught by the wrapper of other languages.

There is a similar issue: apache/pulsar#14582.
However, apache/pulsar#14587 only fixes the case
when creating a `socket`. The exception from the constructor of
`deadline_timer` is not processed.

### Modifications

Handle the exceptions when creating a socket or timer from
`ExecutorService` to restart this executor, then propagate a
`std::runtime_error`. Don't allow creating a timer directly from
`io_service` so that exceptions can be handled well.

In addition, catch the `runtime_error` when:
- Creating a producer (`ProducerImpl` and `PartitionedProducerImpl`)
- Creating a consumer (`ConsumerImpl` and `MultiTopicsConsumerImpl`)
- Creating a reader (`ReaderImpl`)

because the constructors of them all create at least one timer.

### Verifications

Add `tests/unix/ConnectionFailTest.cc` for Unix systems because
`setrlimit` is a POSIX API. It covers the cases when the fd limit is not
enough to create a producer, a consumer and a reader.
@BewareMyPower
BewareMyPower force-pushed the bewaremypower/cnx-exception branch from 6ed4c9c to 769adce Compare February 21, 2023 08:17
Comment thread lib/PartitionedProducerImpl.cc Resolved
@shibd
shibd merged commit 14b0451 into apache:main Mar 2, 2023
@BewareMyPower
BewareMyPower deleted the bewaremypower/cnx-exception branch March 3, 2023 15:52
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.

[Bug] Exception could be thrown when creating producers or consumers

3 participants