Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Tests trying to find unused ports are flakey when automated

Open
#513 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start in tests/test_tcp.py, especially the tests using find_free_port around test_create_server_5 and test_create_server_6. Reproduce the failures in an automated or busy environment, then evaluate using port 0, a shared IPv4/IPv6 socket, or retrying the first socket creation. Done means the tests no longer fail because the selected port is already in use.

Written by the indexing model from the issue text.

Description

  • uvloop version: 0.17.0
  • Python version: 3.10
  • Platform: nix/darwin
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: N/A
  • Does uvloop behave differently from vanilla asyncio? How?: N/A

The tests using find_free_port (like https://github.com/MagicStack/uvloop/blob/d2deffefa18653636eb03ea77a5dab6e4febf6c6/tests/test_tcp.py#L252) may fail in busy CI environments. For example building for nixpkgs involves running tests every time. It ends up with: (https://hydra.nixos.org/build/197525892/nixlog/1)

=================================== FAILURES ===================================
_______________________ Test_UV_TCP.test_create_server_5 _______________________
Traceback (most recent call last):
  File "/private/tmp/tmp.xkcj6kx4o4/tests/test_tcp.py", line 245, in test_create_server_5
    self.loop.run_until_complete(runner())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/private/tmp/tmp.xkcj6kx4o4/tests/test_tcp.py", line 238, in runner
    srv = await self.loop.create_server(
  File "uvloop/loop.pyx", line 1790, in create_server
OSError: [Errno 48] error while attempting to bind on address ('::', 50000, 0, 0): address already in use
_______________________ Test_UV_TCP.test_create_server_6 _______________________
Traceback (most recent call last):
  File "/private/tmp/tmp.xkcj6kx4o4/tests/test_tcp.py", line 271, in test_create_server_6
    self.loop.run_until_complete(runner())
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/private/tmp/tmp.xkcj6kx4o4/tests/test_tcp.py", line 255, in runner
    srv1 = await self.loop.create_server(
  File "uvloop/loop.pyx", line 1790, in create_server
OSError: [Errno 48] error while attempting to bind on address ('::', 50000, 0, 0): address already in use
=============================== warnings summary ===============================

Do those tests need to use a common ipv4/6 socket? Could they use only one protocol at a time with port 0 and then get the local port number from the result?

Or maybe build the retry loop around the first socket creation rather than 2 independent steps?

Dominant language
Cython
Stars
11.9k
Forks
615
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MagicStack/uvloop

All issues in MagicStack/uvloop

Similar issues

More Networking issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.