uvloop icon indicating copy to clipboard operation
uvloop copied to clipboard

uvloop strictly needs SO_REUSEPORT

Open mtelka opened this issue 2 years ago • 3 comments

uvloop expects that SO_REUSEPORT is supported everywhere. Unfortunately, there are some platforms where SO_REUSEPORT is not supported. For example illumos.

Error message:

uvloop/loop.c: In function '__pyx_gb_6uvloop_4loop_4Loop_57generator3':
uvloop/loop.c:33764:46: error: 'SO_REUSEPORT' undeclared (first use in this function); did you mean 'SO_REUSEADDR'?
33764 |             __pyx_t_5 = __Pyx_PyInt_From_int(SO_REUSEPORT); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1778, __pyx_L32_error)
      |                                              ^~~~~~~~~~~~
      |                                              SO_REUSEADDR
uvloop/loop.c:33764:46: note: each undeclared identifier is reported only once for each function it appears in
  • uvloop version: 0.17.0
  • Python version: 3.9.16
  • Platform: OpenIndiana/illumos
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: N/A
  • Does uvloop behave differently from vanilla asyncio? How?: N/A

Could you please detect the SO_REUSEPORT support during build and do not try to use SO_REUSEPORT if it is not available?

Thank you.

mtelka avatar Jul 19 '23 12:07 mtelka

This appears to still be an issue:

uvloop version: 0.19.0 Python version: 3.12.3 Platform: illumos (OmniOS r151050)

cmchittom avatar May 27 '24 23:05 cmchittom

The code correctly detects whether SO_REUSEPORT is available (look for has_SO_REUSEPORT).

Unfortunately, at about line 1778 of uvloop/loop.pyx this code, which is where it's failing:

                    if reuse_port:
                        sock.setsockopt(uv.SOL_SOCKET, uv.SO_REUSEPORT, 1)

is incorrect. The use of uv.SO_REUSEPORT brings in the C version of SO_REUSEPORT which doesn't exist, rather than the python version which does. So the code here should be

                    if reuse_port:
                        sock.setsockopt(uv.SOL_SOCKET, SO_REUSEPORT, 1)

A quick test confirms that, with this change, a build on illumos is successful.

ptribble avatar Jun 19 '24 21:06 ptribble

@ptribble would you mind to create a PR to fix the issue? Thanks.

mtelka avatar Jun 19 '24 22:06 mtelka