From aefbb46c95c98e1dab35485fc7f289b80aacf4da Mon Sep 17 00:00:00 2001 From: Gauresh Rane Date: Mon, 27 Jan 2020 15:38:05 -0800 Subject: [PATCH] Check if server socket instance is non-null Summary: It was a null socket pointer which I don't understand I thought the map should never have that. I checked the server_sockets_ map and did not find a null socket so I am not sure what is happening here. I am adding a critical to get more info ``` (gdb) bt #0 std::chrono::operator==, long, std::ratio<1l, 1000000000l> > (__lhs=..., __rhs=...) at third-party-buck/platform007/build/libgcc/include/c++/trunk/chrono:547 #1 std::chrono::operator== >, std::chrono::duration > > (__lhs=..., __rhs=...) at third-party-buck/platform007/build/libgcc/include/c++/trunk/chrono:754 #2 std::chrono::operator!= >, std::chrono::duration > > (__lhs=..., __rhs=...) at third-party-buck/platform007/build/libgcc/include/c++/trunk/chrono:760 #3 facebook::logdevice::operator!= >, facebook::logdevice::detail::Holder, std::chrono::duration > > (lhs=..., rhs=...) at logdevice/common/Timestamp.h:578 #4 facebook::logdevice::Socket::checkSocketHealth (this=0x0) <========================= *******nullptr****** at logdevice/common/Socket.cpp:2463 #5 0x000000000547779a in facebook::logdevice::Sender::closeSlowSockets ( this=0x7fe209854250) at logdevice/common/Sender.cpp:1612 #6 0x00000000054a3329 in folly::detail::function::FunctionTraits::callSmall(folly::detail::function::Data&) (p=...) at third-party-buck/platform007/build/libgcc/include/c++/trunk/bits/std_function.h:706 #7 0x00000000054c3c95 in folly::detail::function::FunctionTraits::callBig, signed char)::$_9>(folly::detail::function::Data&) (p=...) at folly/Function.h:416 #8 0x0000000005aba867 in folly::detail::function::FunctionTraits::operator()() (this=0x7fe173385c80) at folly/Function.h:416 #9 facebook::logdevice::EventLoopTaskQueue::executeTasks ( this=, tokens=) at logdevice/common/EventLoopTaskQueue.cpp:154 #10 facebook::logdevice::EventLoopTaskQueue::haveTasksEventHandler()::$_1::operator()(unsigned int) const (n=, this=) at logdevice/common/EventLoopTaskQueue.cpp:101 #11 facebook::logdevice::LifoEventSemImpl::AsyncWaiter::processBatch(facebook::logdevice::EventLoopTaskQueue::haveTasksEventHandler()::$_1&, unsigned int) (this=, func=..., maxBatchSize=) at logdevice/common/LifoEventSem.h:368 #12 facebook::logdevice::EventLoopTaskQueue::haveTasksEventHandler ( this=) at logdevice/common/EventLoopTaskQueue.cpp:106 #13 facebook::logdevice::EventLoopTaskQueue::EventLoopTaskQueue(facebook::logdevice::EvBase&, unsigned long, std::array const&)::$_0::operator()() const (this=) at logdevice/common/EventLoopTaskQueue.cpp:36 #14 folly::detail::function::FunctionTraits::callSmall const&)::$_0>(folly::detail::function::Data&) (p=...) at folly/Function.h:387 #15 0x0000000007f8bfb0 in event_process_active_single_queue ( base=0x7fe1e7a1c000, activeq=0x7fe1e7a21010, max_to_process=2147483647, endtime=0x0) at rocketspeed/external/libevent-2.1.3-alpha/event.c:1411 #16 0x0000000007f8b5b8 in ld_event_base_loop (base=0x7fe1e7a1c000, flags=0) at rocketspeed/external/libevent-2.1.3-alpha/event.c:1596 #17 0x000000000784800e in facebook::logdevice::EvBaseLegacy::loop ( this=0x7fe1e7a01018) at logdevice/common/libevent/EvBaseLegacy.cpp:59 #18 0x0000000005ab8795 in std::_Function_handler, std::allocator >, facebook::logdevice::ThreadID::Type, unsigned long, bool, std::array const&, facebook::logdevice::EvBase::EvBaseType, bool)::$_0>::_M_invoke(std::_Any_data const&) (__functor=...) at logdevice/common/EventLoop.cpp:156 #19 0x000000000770bd23 in facebook::logdevice::thread_func ( arg=0x7fe21c8b38a0) at third-party-buck/platform007/build/libgcc/include/c++/trunk/bits/std_function.h:706 #20 0x00007fe225bbe6b6 in start_thread () from /usr/local/fbcode/platform007/lib/libpthread.so.0 #21 0x00007fe22529febf in clone () from /usr/local/fbcode/platform007/lib/libc.so.6 ``` Reviewed By: al13n321 Differential Revision: D19294475 fbshipit-source-id: e705d61277d2ad08245a8cacbcfcd68c127f5c08 --- logdevice/common/Sender.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/logdevice/common/Sender.cpp b/logdevice/common/Sender.cpp index 8e72bcd7a424..cc8c33379ce4 100644 --- a/logdevice/common/Sender.cpp +++ b/logdevice/common/Sender.cpp @@ -1648,10 +1648,29 @@ void Sender::closeSlowSockets() { }; for (auto& entry : impl_->server_conns_) { + Connection* conn = entry.second.get(); + if (conn) { + close_if_slow(*conn); + } else { + RATELIMIT_CRITICAL( + std::chrono::seconds(10), + 1, + "Unexpected null server socket found for nid %u. T59653729", + entry.first); + } close_if_slow(*entry.second); } for (auto& entry : impl_->client_conns_) { - close_if_slow(*entry.second); + Connection* conn = entry.second.get(); + if (conn) { + close_if_slow(*conn); + } else { + RATELIMIT_CRITICAL( + std::chrono::seconds(10), + 1, + "Unexpected null client socket found for cid %s. T59653729", + entry.first.toString().c_str()); + } } if (sockets_closed) { RATELIMIT_WARNING(