Permalink
Browse files

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
  • Loading branch information...
fredemmott committed Jul 13, 2018
1 parent b857ec9 commit 46e5dff56d0d9c0dd296b9f36615e1756bc07c07
Showing with 16 additions and 5 deletions.
  1. +5 −4 CMake/FindLibEvent.cmake
  2. +11 −1 hphp/runtime/base/program-functions.cpp
View
@@ -12,10 +12,11 @@ endforeach()
find_path(LIBEVENT_INCLUDE_DIR event.h PATHS ${LibEvent_INCLUDE_PATHS})
find_library(LIBEVENT_LIB NAMES event PATHS ${LibEvent_LIB_PATHS})
find_library(LIBEVENT_PTHREAD_LIB NAMES event_pthreads PATHS ${LibEvent_LIB_PATHS})
if (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR)
if (LIBEVENT_LIB AND LIBEVENT_INCLUDE_DIR AND LIBEVENT_PTHREAD_LIB)
set(LibEvent_FOUND TRUE)
set(LIBEVENT_LIB ${LIBEVENT_LIB})
set(LIBEVENT_LIB ${LIBEVENT_LIB} ${LIBEVENT_PTHREAD_LIB})
else ()
set(LibEvent_FOUND FALSE)
endif ()
@@ -26,9 +27,9 @@ if (LibEvent_FOUND)
endif ()
else ()
if (LibEvent_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find libevent.")
message(FATAL_ERROR "Could NOT find libevent and libevent_pthread.")
endif ()
message(STATUS "libevent NOT found.")
message(STATUS "libevent and libevent_pthread NOT found.")
endif ()
mark_as_advanced(
@@ -116,6 +116,11 @@
#include <boost/program_options/variables_map.hpp>
#include <boost/filesystem.hpp>
#ifndef FACEBOOK
// Needed on libevent2
#include <event2/thread.h>
#endif
#include <oniguruma.h>
// Onigurama defines UChar to unsigned char, but ICU4C defines it to signed
// 16-bit int. This is supposed to be resolved by ONIG_ESCAPE_UCHAR_COLLISION,
@@ -1646,8 +1651,13 @@ static int execute_program_impl(int argc, char** argv) {
// forget the source for systemlib.php unless we are debugging
if (po.mode != "debug") SystemLib::s_source = "";
// we need to initialize pcre cache table very early
// we need to to initialize these very early
pcre_init();
// this is needed for libevent2 to be thread-safe, which backs Hack ASIO.
#ifndef FACEBOOK
// FB uses a custom libevent 1
evthread_use_pthreads();
#endif
#ifdef ENABLE_ZEND_COMPAT
//

0 comments on commit 46e5dff

Please sign in to comment.