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

uvloop strictly needs SO_REUSEPORT #550

Closed
mtelka opened this issue Jul 19, 2023 · 3 comments · Fixed by #609
Closed

uvloop strictly needs SO_REUSEPORT #550

mtelka opened this issue Jul 19, 2023 · 3 comments · Fixed by #609

Comments

@mtelka
Copy link

mtelka commented Jul 19, 2023

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.

@cmchittom
Copy link

This appears to still be an issue:

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

@ptribble
Copy link
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
Copy link
Author

mtelka commented Jun 19, 2024

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

ptribble added a commit to ptribble/uvloop that referenced this issue Jun 20, 2024
@fantix fantix closed this as completed in 4083a94 Aug 16, 2024
fantix added a commit that referenced this issue Oct 14, 2024
Changes
=======

* Add cleanup_socket param on create_unix_server() (#623)
  (by @fantix in d6114d2)

Fixes
=====

* Use cythonized SO_REUSEPORT rather than the unwrapped native one. (#609)
  (by @ptribble in 4083a94 for #550)

* UDP errors should result in protocol.error_received (#601)
  (by @jensbjorgensen in 3c3bbef)

* Updates for Cython3 (#587)
  (by @alan-brooks in 3fba9fa for #587)

* Test with Python 3.13 (#610)
  (by @edgarrmondragon in fb5a139)
@fantix fantix mentioned this issue Oct 14, 2024
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 a pull request may close this issue.

3 participants