Skip to content

fix(eventio): make _poll.poll(None) block indefinitely - #2862

Closed
tony1233200 wants to merge 2 commits into
celery:mainfrom
tony1233200:fix/2834-poll-none-timeout
Closed

tony1233200 wants to merge 2 commits into
celery:mainfrom
tony1233200:fix/2834-poll-none-timeout

Conversation

@tony1233200

Copy link
Copy Markdown
Contributor

Fixes #2834.

Problem

kombu.utils.eventio._poll.poll() — the poller used wherever epoll is
unavailable (macOS, FreeBSD, OpenBSD) — converted its timeout with
round((timeout or 0) * 1e3), turning None into 0. So poll(None)
called select.poll().poll(0) and returned [] immediately instead of
blocking until an event arrives, unlike _epoll (which passes -1 for
None), _kqueue, and _select (which pass None through).

On Redis, Connection.drain_events() with no timeout passes None down
through MultiChannelPoller.get() to _poll.poll(None), so an idle
consumer on macOS/BSD busy-spins — the issue reports ~35k poll() calls
and ~3.5k restore_visible() cycles in 3 s while waiting for a single
BRPOP reply.

Fix

In _poll.poll():

  • timeout is None → pass -1 (select.poll treats a negative timeout
    as infinite), mirroring _epoll;
  • timeout < 0 → 0, as before;
  • otherwise → round(timeout * 1e3) milliseconds, as before.

Verified with the reproducer from the issue (using _poll directly):
before — poll(None) returned [] after 0.0 s; after — it returns
[(fd, 1)] after 0.5 s, when the timer sends.

Tests

New test__poll class in t/unit/utils/test_eventio.py, mirroring the
existing test__epoll tests:

  • test_poll_none_timeout_passes_minus_one and
    test_poll_none_timeout_blocks_until_event (a real socketpair
    end-to-end check) — both fail on the unpatched code and pass with the
    fix;
  • guards that finite timeouts are still converted to milliseconds and
    negative timeouts still clamp to 0.

t/unit/utils/ — 173 passed; t/unit/asynchronous/ (excluding the aws
modules, which need boto3) — 95 passed, 2 skipped. flake8 clean on
the changed files.

Disclosure: this patch was prepared with the help of an AI coding
assistant and reviewed/tested by me.

_poll.poll() converted the timeout with (timeout or 0), turning None
into 0, so poll(None) returned immediately instead of blocking until
an event arrives -- unlike _epoll (which passes -1), _kqueue and
_select (which pass None through).

On platforms without epoll (macOS, BSD), Connection.drain_events()
with no timeout passes None down to _poll.poll(None), so an idle
consumer busy-spins (the issue reports ~35k poll() calls in 3s while
waiting for a single BRPOP reply).

Pass -1 for a None timeout (select.poll treats a negative timeout as
infinite); finite timeouts are still converted to milliseconds and
negative timeouts still clamp to 0.

Fixes celery#2834.

@auvipy auvipy left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there was already and open PR #2786 under review for that issue, why you opend a duplicate one without checking, and by not checking the contribution guideline? are you real or just another bot contributor? @tony1233200 also you did some distracting drama recently which is very unprofessional. you have been marked as bot for these unprofessional activites

@auvipy

auvipy commented Nov 26, 2026

Copy link
Copy Markdown
Member

@tony1233200 unblocked you again as 2nd chance

@tony1233200

Copy link
Copy Markdown
Contributor Author

Thank you, @auvipy — I appreciate the second chance. I will resume work on the open PRs (#2873–#2876) and follow up on the review feedback there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_poll.poll(None) passes 0 instead of blocking on macOS/BSD, causing drain_events() to busy-spin

2 participants