From: Zejun Wu Date: Tue, 6 May 2014 00:08:36 +0000 (-0700) Subject: Handle event_base_new failure when out of file descriptors. X-Git-Tag: v0.22.0~564 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=fc2b0aa26a044486972ca8f2d526416a01b671d4 Handle event_base_new failure when out of file descriptors. Summary: Both event_base_new and event_init return nullptr when out of file descriptors. Using null event_base will result in segfault. Test Plan: (ulimit -n 50000 && _build/opt/sigma/service/sigma_server --instance_name=si_sigma_push --min_scribe_log_level=0 --allow_status_port_fallback=true --minloglevel=1 --v=0 --feature_objects_limit=1000000 --hbase_default_timeout_ms=250 --max_total_connections_per_region_server=10 --max_retained_connections_per_region_server=10 --tao_default_timeout_ms=5000 --enable_writes_scribe_si_floop=false --enable_writes_all=false --arena_size_limit=268435456 --run_fxl=true) Reviewed By: davejwatson@fb.com FB internal diff: D1311855 --- diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 932a63ac..130ba5fb 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -144,6 +144,10 @@ EventBase::EventBase() , startWork_(0) , observer_(nullptr) , observerSampleCount_(0) { + if (UNLIKELY(evb_ == nullptr)) { + LOG(ERROR) << "EventBase(): Failed to init event base."; + folly::throwSystemError("error in EventBase::EventBase()"); + } VLOG(5) << "EventBase(): Created."; initNotificationQueue(); RequestContext::getStaticContext(); @@ -165,6 +169,10 @@ EventBase::EventBase(event_base* evb) , startWork_(0) , observer_(nullptr) , observerSampleCount_(0) { + if (UNLIKELY(evb_ == nullptr)) { + LOG(ERROR) << "EventBase(): Pass nullptr as event base."; + throw std::invalid_argument("EventBase(): event base cannot be nullptr"); + } initNotificationQueue(); RequestContext::getStaticContext(); }