duxet / hhvm-zmq

ZMQ extension for HHVM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get extension to work

paulm17 opened this issue · comments

commented

Hi,

After compiling I'm getting:

test.sh: line 11: 66361 Segmentation fault ${HPHP_HOME}/hhvm -vDynamicExtensions.0=${DIRNAME}/zmq.so ${DIRNAME}/test.php

I am running Centos 7 minimal, Zeromq 4.0.5 installed and latest hhvm 3.6.0.

Thanks

commented

I am using

Centos 7 minimal
hhvm 3.6 (installed from source)
ZeroMQ 4.0.5

When I go to test, I get:

[root@ip-10-0-0-63 hhvm-zmq-master]# sh test.sh

zmq extension loaded: 1
Core dumped: Segmentation fault
Stack trace in /tmp/stacktrace.20032.log
test.sh: line 11: 20032 Segmentation fault      ${HPHP_HOME}/hhvm -vDynamicExtensions.0=${DIRNAME}/zmq.so ${DIRNAME}/test.php

[root@ip-10-0-0-63 hhvm-zmq-master]# cat /tmp/stacktrace.20032.log

Host: ip-10-0-0-63.ec2.internal
ProcessID: 20032
ThreadID: 7f0d456ae740
ThreadPID: 20032
Name: /usr/local/bin/hhvm
Type: Segmentation fault
Runtime: hhvm
Version: tags/HHVM-3.6.0-0-g6ef13f20da20993dc8bab9eb103f73568618d3e8
DebuggerCount: 0

Arguments: /root/hhvm-zmq-master/test.php
ThreadType: CLI

# 0  __restore_rt at sigaction.c:0
# 1  free at /lib64/libjemalloc.so.1:0
# 2  HPHP::FileData::closeImpl() at /usr/local/bin/hhvm:0
# 3  HPHP::SocketData::~SocketData() at /usr/local/bin/hhvm:0
# 4  HPHP::MixedArray::Release(HPHP::ArrayData*) at /usr/local/bin/hhvm:0
# 5  HPHP::freeDynPropArray(HPHP::ObjectData*) at object-data.cpp:0
# 6  HPHP::ObjectData::release() at /usr/local/bin/hhvm:0
# 7  HPHP::(anonymous namespace)::tearDownFrame(HPHP::ActRec*&, HPHP::Stack&, unsigned char const*&, HPHP::Fault const&)::{lambda()#1}::operator()() const at unwind.cpp:0
# 8  HPHP::(anonymous namespace)::unwind(HPHP::ActRec*&, HPHP::Stack&, unsigned char const*&, HPHP::Fault) at unwind.cpp:0
# 9  HPHP::exception_handler() at /usr/local/bin/hhvm:0
# 10 HPHP::ExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::Func const*, HPHP::Variant const&, HPHP::ObjectData*, HPHP::Class*, HPHP::VarEnv*, HPHP::StringData*, HPHP::ExecutionContext::InvokeFlags) at /usr/local/bin/hhvm:0
# 11 HPHP::ExecutionContext::invokeUnit(HPHP::TypedValue*, HPHP::Unit const*) at /usr/local/bin/hhvm:0
# 12 HPHP::invoke_file(HPHP::String const&, bool, char const*) at builtin-functions.cpp:0
# 13 HPHP::include_impl_invoke(HPHP::String const&, bool, char const*) at /usr/local/bin/hhvm:0
# 14 HPHP::hphp_invoke(HPHP::ExecutionContext*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, HPHP::Array const&, HPHP::VRefParamValue const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool, bool, bool) at /usr/local/bin/hhvm:0
# 15 HPHP::hphp_invoke_simple(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) at /usr/local/bin/hhvm:0
# 16 HPHP::execute_program_impl(int, char**) at program-functions.cpp:0
# 17 HPHP::execute_program(int, char**) at /usr/local/bin/hhvm:0
# 18 main at /usr/local/bin/hhvm:0
# 19 __libc_start_main at /lib64/libc.so.6:0
# 20 _start at /usr/local/bin/hhvm:0

PHP Stacktrace:

#0  send_message(tcp://localhost:5555) called at [/root/hhvm-zmq-master/test.php:25]
commented

Asked the fb team to take a look at this:

[19:14:07] @paulbiss without having looked too closely this looks really suspect to me: https://github.com/duxet/hhvm-zmq/blob/master/zmq.cpp#L116

[19:17:30] @paulbiss it's extracting a raw pointer to a resource- generally not a good idea, and certainly a first place to look for ref-counting bugs (the crash you pasted looks like a double-free)

[19:18:02] @paulbiss in any event I don't have time to build and test this extension, but you might point that line out to the authors and have them peak at some of our builtin extensions for examples of how to better handle resources

[19:18:46] @paulbiss also may be worth adding that for what seems like no reason the socket is being stored in the dynprop array, all they need to do is declare it as a member of the class in ext_zmq.php with a nullable resource type

[20:03:56] @paulbiss duxet: we've been trying to clean up our own extensions, basically we want to avoid using raw pointers and Resource() wrappers, instead prefer SmartPtr and construct resources with newres (which returns SmartPtr)

[20:04:27] @paulbiss Bill Nell has been doing a lot of the cleanup, here's one such diff: facebook/hhvm@3c21493

[20:05:34] @paulbiss I think we're trying to eliminate all calls to getTyped() among other things

commented

This replaces the code: https://github.com/duxet/hhvm-zmq/blob/master/zmq.cpp#L107-117

template<class T>
ALWAYS_INLINE
static SmartPtr<T> getResource(ObjectData* obj, const char* varName) {
  auto var = obj->o_get(varName, true, s_zmqsocket.get());
  if (var.getType() == KindOfNull) {
    return nullptr;
  }
  return cast<T>(var);
}
commented

CentOS 7 Min w/ zmq 4.0.4 HHVM 3.6.0
Same issue even after adjusting lines 107-117 in zmq.cpp and recompiling.

Segment faults - same spot as noted in your output above.