Repository navigation
[fix] Handle exceptions when creating timers when fd limit is reached - #203
Merged
Merged
Conversation
BewareMyPower
requested review from
Demogorgon314,
RobertIndie,
merlimat and
shibd
February 21, 2023 08:12
BewareMyPower
force-pushed
the
bewaremypower/cnx-exception
branch
from
February 21, 2023 08:16
5e1ea72 to
6ed4c9c
Compare
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
force-pushed
the
bewaremypower/cnx-exception
branch
from
February 21, 2023 08:17
6ed4c9c to
769adce
Compare
shibd
approved these changes
Mar 1, 2023
RobertIndie
reviewed
Mar 1, 2023
RobertIndie
approved these changes
Mar 2, 2023
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.
Fixes #202
Motivation
When a
deadline_timeris constructed,boost::system::system_errorwould be thrown if the fd limit is reached. In this case, the following APIs would fail with exception instead of returning aResult:createProducersubscribecreateReaderP.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
Resultto 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 ofdeadline_timeris not processed.Modifications
Handle the exceptions when creating a socket or timer from
ExecutorServiceto restart this executor, then propagate astd::runtime_error. Don't allow creating a timer directly fromio_serviceso that exceptions can be handled well.In addition, catch the
runtime_errorwhen:ProducerImplandPartitionedProducerImpl)ConsumerImplandMultiTopicsConsumerImpl)ReaderImpl)because the constructors of them all create at least one timer.
Verifications
Add
tests/unix/ConnectionFailTest.ccfor Unix systems becausesetrlimitis 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)