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

Correctly handle local_addr in create_connection #30

Closed
wants to merge 1 commit into from

Conversation

breakpointninja
Copy link

@breakpointninja breakpointninja commented May 29, 2016

While trying uvloop with my websocket benchmark tool I get a segmentation fault.

# python wsbench.py -p 1
[1]    7449 segmentation fault (core dumped)  python wsbench.py -p 1

The issue comes from incorrect handling of local_addr in create_connection interface.

This patch corrects this.

stack trace follows:

#0  uv_tcp_bind (handle=0xd31fd0, addr=addr@entry=0x0, flags=flags@entry=0) at src/uv-common.c:237
#1  0x00007fffebb832ca in __pyx_f_6uvloop_4loop___tcp_bind (__pyx_v_addr=__pyx_v_addr@entry=0x0, __pyx_v_flags=__pyx_v_flags@entry=0, 
    __pyx_v_handle=0xd31db8) at uvloop/loop.c:63715
#2  0x00007fffebb833f6 in __pyx_f_6uvloop_4loop_12TCPTransport_bind (__pyx_v_self=0xd31db8, __pyx_v_addr=0x0, __pyx_optional_args=<optimized out>)
    at uvloop/loop.c:65306
#3  0x00007fffebc059d7 in __pyx_gb_6uvloop_4loop_4Loop_52generator2 (__pyx_generator=0x7fffefeb71c8, __pyx_sent_value=<optimized out>)
    at uvloop/loop.c:23412
#4  0x00007fffebb63c32 in __Pyx_Coroutine_SendEx (self=0x7fffefeb71c8, value=0x7fffe8fb4ec8) at uvloop/loop.c:111622
#5  0x00007fffebb70a27 in __Pyx_Coroutine_FinishDelegation (gen=0x7fffefeb71c8) at uvloop/loop.c:111653
#6  __Pyx_Generator_Next (self=0x7fffefeb71c8) at uvloop/loop.c:46206
#7  0x00000000004f65f4 in PyEval_EvalFrameEx (f=f@entry=0xc78d68, throwflag=throwflag@entry=0) at Python/ceval.c:2042
#8  0x0000000000591e7c in gen_send_ex (exc=0, arg=arg@entry=0x0, gen=gen@entry=0x7fffefeab780) at Objects/genobject.c:125
#9  _PyGen_Send (gen=gen@entry=0x7fffefeab780, arg=arg@entry=0x869fc0 <_Py_NoneStruct>) at Objects/genobject.c:223
#10 0x00000000004f5012 in PyEval_EvalFrameEx (f=f@entry=0x7fffefea3c18, throwflag=throwflag@entry=0) at Python/ceval.c:2038
#11 0x0000000000591e7c in gen_send_ex (exc=0, arg=arg@entry=0xd25a68, gen=gen@entry=0x7fffefeab830) at Objects/genobject.c:125
#12 _PyGen_Send (gen=gen@entry=0x7fffefeab830, arg=arg@entry=0x869fc0 <_Py_NoneStruct>) at Objects/genobject.c:223
#13 0x00000000004f5012 in PyEval_EvalFrameEx (f=f@entry=0x7fffefea3a68, throwflag=throwflag@entry=0) at Python/ceval.c:2038
#14 0x0000000000591e7c in gen_send_ex (exc=0, arg=arg@entry=0x7fffebb70d0d <__Pyx_PyObject_CallMethod1+541>, gen=gen@entry=0x7fffefeab7d8)
    at Objects/genobject.c:125
#15 _PyGen_Send (gen=gen@entry=0x7fffefeab7d8, arg=arg@entry=0x869fc0 <_Py_NoneStruct>) at Objects/genobject.c:223
#16 0x00000000004f5012 in PyEval_EvalFrameEx (f=f@entry=0xc78a58, throwflag=throwflag@entry=0) at Python/ceval.c:2038
#17 0x0000000000591e7c in gen_send_ex (exc=0, arg=arg@entry=0x7ffff05e0298, gen=gen@entry=0x7fffefeab728) at Objects/genobject.c:125
#18 _PyGen_Send (gen=gen@entry=0x7fffefeab728, arg=arg@entry=0x869fc0 <_Py_NoneStruct>) at Objects/genobject.c:223
#19 0x00000000004f5012 in PyEval_EvalFrameEx (f=f@entry=0xc5edb8, throwflag=throwflag@entry=0) at Python/ceval.c:2038
#20 0x0000000000591e7c in gen_send_ex (exc=0, arg=<optimized out>, gen=0x7fffeb641888) at Objects/genobject.c:125
#21 _PyGen_Send (gen=0x7fffeb641888, arg=<optimized out>) at Objects/genobject.c:223
#22 0x000000000059a50c in PyCFunction_Call (func=0x7fffeb8e3438, args=0x7fffec0adef0, kwds=<optimized out>) at Objects/methodobject.c:134
#23 0x00007fffebb53d50 in __Pyx_PyObject_Call (func=0x7fffeb8e3438, arg=0x7fffec0adef0, kw=0x0) at uvloop/loop.c:109754
#24 0x00007fffebbc31d1 in __pyx_f_6uvloop_4loop_8BaseTask__fast_step (__pyx_v_self=0x7fffeb6570e0, __pyx_v_exc=0x869fc0 <_Py_NoneStruct>)
    at uvloop/loop.c:95300
#25 0x00007fffebbb3fb3 in __pyx_f_6uvloop_4loop_8BaseTask__fast_wakeup (__pyx_v_self=0x7fffeb6570e0, __pyx_v_future=<optimized out>)
    at uvloop/loop.c:96581
---Type <return> to continue, or q <return> to quit--- 
#26 0x00007fffebb57e24 in __pyx_pf_6uvloop_4loop_8BaseTask_6_wakeup (__pyx_v_future=<optimized out>, __pyx_v_self=0x7fffeb6570e0)
    at uvloop/loop.c:96878
#27 __pyx_pw_6uvloop_4loop_8BaseTask_7_wakeup (__pyx_v_self=0x7fffeb6570e0, __pyx_v_future=<optimized out>) at uvloop/loop.c:31321
#28 0x000000000059a50c in PyCFunction_Call (func=0x7fffeb649dc8, args=0x7fffe8fb1c50, kwds=<optimized out>) at Objects/methodobject.c:134
#29 0x00007fffebb53d50 in __Pyx_PyObject_Call (func=0x7fffeb649dc8, arg=0x7fffe8fb1c50, kw=0x0) at uvloop/loop.c:109754
#30 0x00007fffebb68dd4 in __pyx_f_6uvloop_4loop_6Handle__run (__pyx_v_self=__pyx_v_self@entry=0x7fffe902d6a8) at uvloop/loop.c:37148
#31 0x00007fffebbe5eb6 in __pyx_f_6uvloop_4loop_4Loop__on_idle (__pyx_v_self=<optimized out>) at uvloop/loop.c:8194
#32 0x00007fffebb68e21 in __pyx_f_6uvloop_4loop_6Handle__run (__pyx_v_self=__pyx_v_self@entry=0x7fffeb652d90) at uvloop/loop.c:37182
#33 0x00007fffebb9acee in __pyx_f_6uvloop_4loop_cb_idle_callback (__pyx_v_handle=<optimized out>) at uvloop/loop.c:44897
#34 0x00007fffebc2ad94 in uv__run_idle (loop=loop@entry=0xc5de60) at src/unix/loop-watcher.c:68
#35 0x00007fffebc28ef0 in uv_run (loop=0xc5de60, mode=mode@entry=UV_RUN_DEFAULT) at src/unix/core.c:347
#36 0x00007fffebb84c78 in __pyx_f_6uvloop_4loop_4Loop___run (__pyx_v_self=0xc1f558, __pyx_v_mode=UV_RUN_DEFAULT) at uvloop/loop.c:8903
#37 0x00007fffebb88d40 in __pyx_f_6uvloop_4loop_4Loop__run (__pyx_v_self=0xc1f558, __pyx_v_mode=UV_RUN_DEFAULT) at uvloop/loop.c:9218
#38 0x00007fffebbbeadc in __pyx_pf_6uvloop_4loop_4Loop_20run_forever (__pyx_v_self=0xc1f558) at uvloop/loop.c:18087
#39 __pyx_pw_6uvloop_4loop_4Loop_21run_forever (__pyx_v_self=0xc1f558, unused=<optimized out>) at uvloop/loop.c:17988
#40 0x00000000004f6ffc in call_function (oparg=<optimized out>, pp_stack=0x7fffffffd550) at Python/ceval.c:4634
#41 PyEval_EvalFrameEx (f=f@entry=0x7fffeb8e8048, throwflag=throwflag@entry=0) at Python/ceval.c:3185
#42 0x00000000004f610c in fast_function (nk=<optimized out>, na=<optimized out>, n=1, pp_stack=0x7fffffffd650, func=0x7fffeb652c80)
    at Python/ceval.c:4754
#43 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd650) at Python/ceval.c:4681
#44 PyEval_EvalFrameEx (f=f@entry=0x9ae308, throwflag=throwflag@entry=0) at Python/ceval.c:3185
#45 0x00000000004f83fe in _PyEval_EvalCodeWithName (_co=_co@entry=0x7ffff7e79540, globals=globals@entry=0x7ffff05f1e30, 
    locals=locals@entry=0x7ffff05f1e30, args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=0, defs=0x0, defcount=0, 
    kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:3966
#46 0x00000000004f84ff in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, 
    locals=locals@entry=0x7ffff05f1e30, globals=globals@entry=0x7ffff05f1e30, _co=_co@entry=0x7ffff7e79540) at Python/ceval.c:3987
#47 PyEval_EvalCode (co=co@entry=0x7ffff7e79540, globals=globals@entry=0x7ffff7f38548, locals=locals@entry=0x7ffff7f38548) at Python/ceval.c:777
#48 0x0000000000522dff in run_mod (arena=0x9403f0, flags=0x7fffffffd8e0, locals=0x7ffff7f38548, globals=0x7ffff7f38548, filename=0x7ffff05f1e30, 
    mod=0x9c5638) at Python/pythonrun.c:970
#49 PyRun_FileExFlags (fp=0x9ae2f0, filename_str=<optimized out>, start=<optimized out>, globals=0x7ffff7f38548, locals=0x7ffff7f38548, closeit=1, 
    flags=0x7fffffffd8e0) at Python/pythonrun.c:923
#50 0x000000000052300c in PyRun_SimpleFileExFlags (fp=0x9ae2f0, filename=<optimized out>, closeit=1, flags=0x7fffffffd8e0) at Python/pythonrun.c:396
---Type <return> to continue, or q <return> to quit---
#51 0x0000000000421159 in run_file (p_cf=0x7fffffffd8e0, filename=0x8dd390 L"wsbench.py", fp=0x9ae2f0) at Modules/main.c:318
#52 Py_Main (argc=argc@entry=4, argv=argv@entry=0x8dc010) at Modules/main.c:768
#53 0x000000000041c2a8 in main (argc=4, argv=<optimized out>) at ./Programs/python.c:69

@1st1
Copy link
Member

1st1 commented May 29, 2016

Thanks! Could you please write a unittest for this?

@@ -1371,10 +1371,10 @@ cdef class Loop:
0) # 0 == don't unpack

fs.append(f2)
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the else is important here.

@1st1
Copy link
Member

1st1 commented May 29, 2016

Should be fixed in 37a0b15. It would be great if you can create a regression test for this.

@breakpointninja
Copy link
Author

Thanks! I wish I had the time to do the tests. 👍

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

Successfully merging this pull request may close these issues.

2 participants