Skip to content

eventlet Timer: cancelling a repeating timer does not stop it #11160

Backlog

Description

@AliMuhammadAslam

Checklist

  • I have verified that the issue exists against the main branch of Celery.
  • This has already been asked to the discussions forum first.
  • I have read the relevant section in the
    contribution guide
    on reporting bugs.
  • I have checked the issues list
    for similar or identical bug reports.
  • I have checked the pull requests list
    for existing proposed fixes.
  • I have checked the commit log
    to find out if the bug was already fixed in the main branch.
  • I have included all related issues and possible duplicate issues
    in this issue (If there are none, check this box anyway).
  • I have tried to reproduce the issue with pytest-celery and added the reproduction script below.

Mandatory Debugging Information

  • I have included the output of celery -A proj report in the issue.
    (if you are not able to do this, then at least specify the Celery
    version affected).
  • I have verified that the issue exists against the main branch of Celery.
  • I have included the contents of pip freeze in the issue.
  • I have included all the versions of all the external dependencies required
    to reproduce this bug.

Optional Debugging Information

  • I have tried reproducing the issue on more than one Python version
    and/or implementation.
  • I have tried reproducing the issue on more than one message broker and/or
    result backend.
  • I have tried reproducing the issue on more than one version of the message
    broker and/or result backend.
  • I have tried reproducing the issue on more than one operating system.
  • I have tried reproducing the issue on more than one workers pool.
  • I have tried reproducing the issue with autoscaling, retries,
    ETA/Countdown & rate limits disabled.
  • I have tried reproducing the issue after downgrading
    and/or upgrading Celery and its dependencies.

Related Issues and Possible Duplicates

Related Issues

  • None

Possible Duplicates

  • None

Environment & Settings

Celery version: 5.7.0 (main at 0b6df69)

Steps to Reproduce

Required Dependencies

  • Minimal Python Version: N/A or Unknown (tested on 3.12)
  • Minimal Celery Version: N/A or Unknown (tested on 5.7.0)
  • Minimal Kombu Version: N/A or Unknown (tested on 5.7.0)
  • Minimal Broker Version: N/A
  • Minimal Result Backend Version: N/A
  • Minimal OS and/or Kernel Version: N/A or Unknown
  • Minimal Broker Client Version: N/A
  • Minimal Result Backend Client Version: N/A

Python Packages

celery 5.7.0, kombu 5.7.0, eventlet 0.41.3, greenlet 3.5.6

Other Dependencies

N/A

Minimally Reproducible Test Case

import eventlet
eventlet.monkey_patch()

from celery.concurrency.eventlet import Timer

timer = Timer()
ticks = []
handle = timer.call_repeatedly(0.05, lambda: ticks.append(1))
eventlet.sleep(0.18)
handle.cancel()  # same with timer.cancel(handle)
n = len(ticks)
eventlet.sleep(0.3)
print(len(ticks) - n)  # prints 5, expected 0

Expected Behavior

Cancelling a timer stops it.

Actual Behavior

call_repeatedly() returns the greenthread of the first tick, and GreenThread.cancel() does nothing once that greenthread has run. The entry is never marked canceled, so the timer keeps rescheduling itself. The same happens with clear() while a callback is running, and an entry canceled with entry.cancel() still runs.

In a worker this means every broker reconnect leaves another Heart/Gossip timer running. Starting and stopping Heart 20 times with a 0.05 s interval gave 336 heartbeats per second afterwards instead of about 20.

I have a fix with tests and will open a PR for it.

Activity

  1. AliMuhammadAslam commented on Nov 24, 2026

    @AliMuhammadAslam
    Author

    Fixed in #11161, with regression tests that fail on main.

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

      Development

      No branches or pull requests

      Issue actions