You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/07 20:32:12 UTC

[GitHub] [pulsar] merlimat opened a new pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

merlimat opened a new pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587


   ### Motivation
   
   Fix #14582
   
   Asio socket creation throws a C++ exception if it fails to create the native socket resource. We need to handle and close the connection.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] github-actions[bot] commented on pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587#issuecomment-1061108480


   @merlimat:Thanks for your contribution. For this PR, do we need to update docs?
   (The [PR template contains info about doc](https://github.com/apache/pulsar/blob/master/.github/PULL_REQUEST_TEMPLATE.md#documentation), which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587#discussion_r821280374



##########
File path: pulsar-client-cpp/lib/ClientConnection.cc
##########
@@ -173,12 +172,20 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
       physicalAddress_(physicalAddress),
       cnxString_("[<none> -> " + physicalAddress + "] "),
       incomingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      connectTimeoutTask_(std::make_shared<PeriodicTask>(executor_->getIOService(),
-                                                         clientConfiguration.getConnectionTimeout())),
       outgoingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      consumerStatsRequestTimer_(executor_->createDeadlineTimer()),
       maxPendingLookupRequest_(clientConfiguration.getConcurrentLookupRequest()) {
 
+    try {
+        socket_ = executor_->createSocket();
+        connectTimeoutTask_ = std::make_shared<PeriodicTask>(executor_->getIOService(),
+                                                             clientConfiguration.getConnectionTimeout());
+        consumerStatsRequestTimer_ = executor_->createDeadlineTimer();
+    } catch (std::exception& e) {

Review comment:
       It's better to catch a `boost::system::system_error` here instead of a raw `std::exception`.
   
   BTW, I think the constructor should not throw an exception, see https://github.com/apache/pulsar/blob/32c3cd1009eea884e0701143fe01dadf4556e73b/pulsar-client-cpp/lib/ExecutorService.cc#L63
   
   It uses [the 1st overloaded constructor](https://www.boost.org/doc/libs/1_77_0/doc/html/boost_asio/reference/basic_stream_socket/basic_stream_socket/overload1.html) that doesn't open a socket, so no exception should be thrown.
   
   Instead, the [3rd overloaded constructor](https://www.boost.org/doc/libs/1_77_0/doc/html/boost_asio/reference/basic_stream_socket/basic_stream_socket/overload1.html) opens the socket, in this case a `system_error` could be thrown.
   
   > [Exceptions](https://www.boost.org/doc/libs/1_77_0/doc/html/boost_asio/reference/basic_stream_socket/basic_stream_socket/overload3.html#boost_asio.reference.basic_stream_socket.basic_stream_socket.overload3.exceptions)
   >
   > boost::system::system_error
   > Thrown on failure.
   
   
   Could you confirm the exception was thrown here?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587#discussion_r821331929



##########
File path: pulsar-client-cpp/lib/ClientConnection.cc
##########
@@ -173,12 +172,20 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
       physicalAddress_(physicalAddress),
       cnxString_("[<none> -> " + physicalAddress + "] "),
       incomingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      connectTimeoutTask_(std::make_shared<PeriodicTask>(executor_->getIOService(),
-                                                         clientConfiguration.getConnectionTimeout())),
       outgoingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      consumerStatsRequestTimer_(executor_->createDeadlineTimer()),
       maxPendingLookupRequest_(clientConfiguration.getConcurrentLookupRequest()) {
 
+    try {
+        socket_ = executor_->createSocket();
+        connectTimeoutTask_ = std::make_shared<PeriodicTask>(executor_->getIOService(),
+                                                             clientConfiguration.getConnectionTimeout());
+        consumerStatsRequestTimer_ = executor_->createDeadlineTimer();
+    } catch (std::exception& e) {

Review comment:
       I've confirmed. It looks like this exception was not documented well in Boost.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587#discussion_r821332735



##########
File path: pulsar-client-cpp/lib/ClientConnection.cc
##########
@@ -173,12 +172,20 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
       physicalAddress_(physicalAddress),
       cnxString_("[<none> -> " + physicalAddress + "] "),
       incomingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      connectTimeoutTask_(std::make_shared<PeriodicTask>(executor_->getIOService(),
-                                                         clientConfiguration.getConnectionTimeout())),
       outgoingBuffer_(SharedBuffer::allocate(DefaultBufferSize)),
-      consumerStatsRequestTimer_(executor_->createDeadlineTimer()),
       maxPendingLookupRequest_(clientConfiguration.getConcurrentLookupRequest()) {
 
+    try {
+        socket_ = executor_->createSocket();
+        connectTimeoutTask_ = std::make_shared<PeriodicTask>(executor_->getIOService(),
+                                                             clientConfiguration.getConnectionTimeout());
+        consumerStatsRequestTimer_ = executor_->createDeadlineTimer();
+    } catch (std::exception& e) {

Review comment:
       ```suggestion
       } catch (const boost::system::system_error& e) {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] codelipenghui merged pull request #14587: [C++] Handle exception in creating socket when fd limit is reached

Posted by GitBox <gi...@apache.org>.
codelipenghui merged pull request #14587:
URL: https://github.com/apache/pulsar/pull/14587


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org