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

Reader keeps querying nsqlookupd after reader.close() if it's called too quickly #261

Open
dettonijr opened this issue Dec 31, 2021 · 1 comment
Labels

Comments

@dettonijr
Copy link

dettonijr commented Dec 31, 2021

import nsq
import tornado

reader = nsq.Reader(
    lookupd_http_addresses=["localhost:4161"],
    topic="topic",
    channel="channel",
    message_handler=lambda msg: None,
    lookupd_poll_interval=5,
    lookupd_poll_jitter=1.0,
)

ioloop = tornado.ioloop.IOLoop.current()

# Very quick, but this needs to run after reader._run
# EDIT: Ignore the following 2 lines. The reason it needs to be after _run is because it needs to schedule the callback that will trigger the bug. Thinking now, I guess "add_callback" should actually reproduce, but I remember it didn't.
# Because there's another bug in `reader.close` if self.redist_periodic is None
# In theory we should be able to just add_callback here without call_later, or even just call `reader.close()`
ioloop.call_later(0.1, reader.close)

# Callback just to make the program end eventually, not necessary to reproduce the bug
ioloop.call_later(300, ioloop.stop)
nsq.run()

The example above will (most of the times) keep querying nsqlookupd every 5 seconds, even after reader.close was called

This seems to be because this delayed callback never gets canceled
https://github.com/nsqio/pynsq/blob/master/nsq/reader.py#L263

Note: Because of the random() in the delay, it "works sometimes" when random is a very small number

@ploxiln ploxiln added the bug label Jan 1, 2022
@dettonijr dettonijr changed the title Reader keeps querying nsqlookupd after reader.close() if it's was called too quick Reader keeps querying nsqlookupd after reader.close() if it's called too quickly Jan 5, 2022
@mreiferson
Copy link
Member

Yep, good catch. Are you interested in opening a PR to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants