Skip to content

uvloop strictly needs SO_REUSEPORT #550

Closed
@mtelka

Description

@mtelka

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.

Activity

cmchittom

cmchittom commented on May 27, 2024

@cmchittom

This appears to still be an issue:

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

ptribble

ptribble commented on Jun 19, 2024

@ptribble
Contributor

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.

mtelka

mtelka commented on Jun 19, 2024

@mtelka
Author

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

added a commit that references this issue on Jun 20, 2024
48d0b1e
added a commit that references this issue on Aug 16, 2024
4083a94
added a commit that references this issue on Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @cmchittom@ptribble@mtelka

      Issue actions

        uvloop strictly needs SO_REUSEPORT · Issue #550 · MagicStack/uvloop