-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
network: cleanup connection logic and crash when fd cannot be allocat…
…ed (#237) The fix in 8d5366 looks good. This commit further cleans up the socket close logic to make it simpler and more unified. It also changes the behavior to crash the process if we can't allocate a socket or we have an error during accept. In practice those only happen when we run out of FDs which should be considered an OOM condition where we also crash on purpose.
- Loading branch information
1 parent
8d53667
commit 210b5dd
Showing
11 changed files
with
82 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "common/network/listener_impl.h" | ||
#include "common/stats/stats_impl.h" | ||
|
||
#include "test/mocks/network/mocks.h" | ||
|
||
using testing::_; | ||
using testing::Invoke; | ||
|
||
namespace Network { | ||
|
||
static void errorCallbackTest() { | ||
// Force the error callback to fire by closing the socket under the listener. We run this entire | ||
// test in the forked process to avoid confusion when the fork happens. | ||
Stats::IsolatedStoreImpl stats_store; | ||
Event::DispatcherImpl dispatcher; | ||
Network::TcpListenSocket socket(10000); | ||
Network::MockListenerCallbacks listener_callbacks; | ||
Network::ListenerPtr listener = | ||
dispatcher.createListener(socket, listener_callbacks, stats_store, false); | ||
|
||
Network::ClientConnectionPtr client_connection = | ||
dispatcher.createClientConnection("tcp://127.0.0.1:10000"); | ||
client_connection->connect(); | ||
|
||
EXPECT_CALL(listener_callbacks, onNewConnection_(_)) | ||
.WillOnce(Invoke([&](Network::ConnectionPtr& conn) -> void { | ||
client_connection->close(ConnectionCloseType::NoFlush); | ||
conn->close(ConnectionCloseType::NoFlush); | ||
socket.close(); | ||
})); | ||
|
||
dispatcher.run(Event::Dispatcher::RunType::Block); | ||
} | ||
|
||
TEST(ListenerImplDeathTest, ErrorCallback) { | ||
EXPECT_DEATH(errorCallbackTest(), ".*listener accept failure.*"); | ||
} | ||
|
||
} // Network |
This file contains 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