Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHVM incorrect behavior for stream_socket_sendto() #713

Closed
rbakshi opened this issue Mar 18, 2013 · 2 comments
Closed

HHVM incorrect behavior for stream_socket_sendto() #713

rbakshi opened this issue Mar 18, 2013 · 2 comments

Comments

@rbakshi
Copy link

rbakshi commented Mar 18, 2013

I have encountered an incorrect behavior while running PHP code over HHVM and fixed it. Could you review the change? If it is good to go it can be taken up by HHVM.


I am running our PHP code over HHVM. The code makes a call stream_socket_sendto(). This call does not work and the error message received is "Transport endpoint is already connected".

  • f_socket_sendto() in HHVM is executed for the PHP call to stream_socket_sendto()
  • socket type is AF_UNIX
  • sendto() is called and it returns EISCONN (Transport endpoint is already connected)

Debugged HHVM code and following are the details.

Back trace:
#0 HPHP::f_stream_socket_sendto (socket=..., data=..., flags=0, address=...)

at /home/zlive/dev/hiphop-php/hphp/runtime/ext/ext_stream.cpp:388

#1 0x0000000001595ad4 in HPHP::fg_stream_socket_sendto (ar=0x7fffe5dbff50)

at /home/zlive/dev/hiphop-php/hphp/runtime/ext/ext_stream.ext_hhvm.cpp:1182

#2 0x0000000000efea86 in iopNativeImpl (this=0x7fffecb51c00, numInstrs=-438567104)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:6786

#3 HPHP::VMExecutionContext::dispatchImpl<0> (this=0x7fffecb51c00, numInstrs=-438567104)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:7392

#4 0x0000000000eec5af in dispatch (this=0x7fffecb51c00, enterFnAr=)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:7415

#5 HPHP::VMExecutionContext::enterVMWork (this=0x7fffecb51c00, enterFnAr=)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:1880

#6 0x0000000000eec9fe in HPHP::VMExecutionContext::enterVM (this=0x7fffecb51c00, retval=0x7fffffffd770, ar=0x7fffe5dbffc0, extraArgs=0x0)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:1964

#7 0x0000000000eed63f in HPHP::VMExecutionContext::invokeFunc (this=0x7fffecb51c00, retval=0x7fffffffd770, f=0x7fffe6337380,

params=<value optimized out>, this_=<value optimized out>, cls=<value optimized out>, varEnv=0x7fffe5d55000, invName=0x0,
toMerge=0x7fffe6de8c00) at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:2204

#8 0x0000000000eedc39 in HPHP::VMExecutionContext::invokeUnit (this=0x7fffecb51c00, retval=0x7fffffffd770, unit=0x7fffe6de8c00)

at /home/zlive/dev/hiphop-php/hphp/runtime/vm/bytecode.cpp:2243

#9 0x0000000000cfd2eb in HPHP::eval_invoke_file_hook (res=..., path=, once=,

variables=<value optimized out>, currentDir=<value optimized out>) at /home/zlive/dev/hiphop-php/hphp/runtime/eval/eval.cpp:57

#10 0x00000000008a3669 in HPHP::invoke_file (s=..., once=true, variables=, currentDir=)

at /home/zlive/dev/hiphop-php/hphp/hhvm/externals_stubs.cpp:47

#11 0x0000000000ba87e5 in HPHP::include_impl_invoke (file=..., once=true, variables=0x0, currentDir=0x18be538 "")

at /home/zlive/dev/hiphop-php/hphp/runtime/base/builtin_functions.cpp:1663

#12 0x0000000000bd7e1f in hphp_invoke (argc=3, argv=0x7fffffffe5a8)

at /home/zlive/dev/hiphop-php/hphp/runtime/base/program_functions.cpp:1365

#13 hphp_invoke_simple (argc=3, argv=0x7fffffffe5a8) at /home/zlive/dev/hiphop-php/hphp/runtime/base/program_functions.cpp:1336
#14 HPHP::execute_program_impl (argc=3, argv=0x7fffffffe5a8) at /home/zlive/dev/hiphop-php/hphp/runtime/base/program_functions.cpp:1101
#15 0x0000000000bd8da8 in HPHP::execute_program (argc=3, argv=0x7fffffffe5a8)

at /home/zlive/dev/hiphop-php/hphp/runtime/base/program_functions.cpp:713

#16 0x00000000008a26eb in main (argc=3, argv=0x7fffffffe5a8) at /home/zlive/dev/hiphop-php/hphp/hhvm/main.cpp:41

Highlighting the code portion that is executed and the error returned from f_socket_sendto():

Variant f_socket_sendto(CObjRef socket, CStrRef buf, int len, int flags,
CStrRef addr, int port /* = 0 */) {
...
switch (sock->getType()) {
...
case AF_UNIX:
retval = sendto(sock->fd(), buf, len, flags,
(struct sockaddr *)&s_un, SUN_LEN(&s_un));
}
...
}
if (retval == -1) {
SOCKET_ERROR(sock, "unable to write to socket", errno);
return false;
}
...
if (retval == -1) {
SOCKET_ERROR(sock, "unable to write to socket", errno);
return false;
}
...
}


Fix :

I looked at man page of sendto() and it says following:
...
If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) socket, the parameters to and tolen are ignored (and the error EISCONN may be returned when they are not NULL and 0), and the error ENOTCONN is returned when the socket was not actually connected.
...

In our context, we are using SOCK_STREAM.
Keeping the last two arguments to NULL and 0 are working fine and as expected.
So the change is :

File: hphp/runtime/ext/ext_socket.cpp
769 //Ensure the clause is executed conservatively for SOCK_STREAM
770 //only and for other sockets keep the execution as before
771 retval = sendto(sock->fd(), buf, len, flags,
772 NULL, 0); //Line Added
773 //(struct sockaddr *)&s_un, SUN_LEN(&s_un)); //Line Deleted

Afterwards it is working fine for the PHP code.

I am running HHVM on CnetOS-6.2.
[]$ uname -a
Linux zlive-platform-dapi-infra-dev-hhvmdebug-03 2.6.32-220.23.1.el6.x86_64 #1 SMP Mon Jun 18 18:58:52 BST 2012 x86_64 x86_64 x86_64 GNU/Linux

@ghost ghost assigned scottmac and paroski May 12, 2013
@ghost ghost assigned ptarjan May 21, 2013
@ptarjan
Copy link
Contributor

ptarjan commented Dec 7, 2013

Can you post some sample code? I tried your explanation but can't get it to hook up correctly.

@ptarjan ptarjan closed this as completed Dec 7, 2013
@scannell
Copy link
Contributor

scannell commented Dec 7, 2013

To close the loop, this is not actionable at the moment and the issue is months also so we're closing it. If someone has a working repro [it may have been fixed by now as this was months ago] or a fix for it, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants