Skip to content

Commit 9db89dc

Browse files
committed
Call evthread_use_pthreads() on startup (#8258)
Summary: libevent2 is not thread-safe without this. - `[err] evmap.c:779: Assertion fdinfo->idxplus1 == i + 1 failed in event_changelist_remove_all_` - #8230 Pull Request resolved: #8258 Reviewed By: fugalh Differential Revision: D8822279 Pulled By: fredemmott fbshipit-source-id: 77365718fb4defee5c07eb9eb7a1da728cc01946
1 parent 101d324 commit 9db89dc

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎CMake/FindLibEvent.cmake‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ endforeach()
1212

1313
find_path(LIBEVENT_INCLUDE_DIR event.h PATHS ${LibEvent_INCLUDE_PATHS})
1414
find_library(LIBEVENT_LIB NAMES event PATHS ${LibEvent_LIB_PATHS})
15+
find_library(LIBEVENT_PTHREAD_LIB NAMES event_pthreads PATHS ${LibEvent_LIB_PATHS})
1516

16-
if (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR)
17+
if (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR AND LIBEVENT_PTHREAD_LIB)
1718
set(LibEvent_FOUND TRUE)
18-
set(LIBEVENT_LIB ${LIBEVENT_LIB})
19+
set(LIBEVENT_LIB ${LIBEVENT_LIB} ${LIBEVENT_PTHREAD_LIB})
1920
else ()
2021
set(LibEvent_FOUND FALSE)
2122
endif ()
@@ -26,9 +27,9 @@ if (LibEvent_FOUND)
2627
endif ()
2728
else ()
2829
if (LibEvent_FIND_REQUIRED)
29-
message(FATAL_ERROR "Could NOT find libevent.")
30+
message(FATAL_ERROR "Could NOT find libevent and libevent_pthread.")
3031
endif ()
31-
message(STATUS "libevent NOT found.")
32+
message(STATUS "libevent and libevent_pthread NOT found.")
3233
endif ()
3334

3435
mark_as_advanced(

‎hphp/runtime/base/program-functions.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
#include <boost/program_options/variables_map.hpp>
120120
#include <boost/filesystem.hpp>
121121

122+
#ifndef FACEBOOK
123+
// Needed on libevent2
124+
#include <event2/thread.h>
125+
#endif
126+
122127
#include <oniguruma.h>
123128
// Onigurama defines UChar to unsigned char, but ICU4C defines it to signed
124129
// 16-bit int. This is supposed to be resolved by ONIG_ESCAPE_UCHAR_COLLISION,
@@ -1743,8 +1748,13 @@ static int execute_program_impl(int argc, char** argv) {
17431748
RuntimeOption::VSDebuggerNoWait = po.vsDebugNoWait;
17441749
}
17451750

1746-
// we need to initialize pcre cache table very early
1751+
// we need to to initialize these very early
17471752
pcre_init();
1753+
// this is needed for libevent2 to be thread-safe, which backs Hack ASIO.
1754+
#ifndef FACEBOOK
1755+
// FB uses a custom libevent 1
1756+
evthread_use_pthreads();
1757+
#endif
17481758

17491759
tl_heap.getCheck();
17501760
if (RuntimeOption::ServerExecutionMode()) {

0 commit comments

Comments
 (0)