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

Bug: Subscribers registered in runtime do not clean up after close #2053

Open
saschnet opened this issue Jan 24, 2025 · 1 comment
Open

Bug: Subscribers registered in runtime do not clean up after close #2053

saschnet opened this issue Jan 24, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@saschnet
Copy link

saschnet commented Jan 24, 2025

I am trying to use the new dynamic subscription from https://github.com/airtai/faststream/releases/tag/0.5.0 (see point number 9).

While adding the dynamic subscription works well, I have issues closing the dynamic subscription. See the following example, where I start a subscription and immediately stop it. Hence, the message that is published afterwards, must not be picked up by the handler.

Running the code below raises the exception in the handler, as it is executed.

I was also able to replicate this behavior using a real NATS server, hence, this is not a bug in the TestNatsBroker implementation.

How to reproduce

import asyncio
from faststream.nats import NatsBroker, TestNatsBroker
from faststream.nats.subscriber.asyncapi import AsyncAPISubscriber


async def start_stop(broker: NatsBroker) -> None:
    def handler_method() -> None:
        raise ValueError("This must never be executed")

    subscriber: AsyncAPISubscriber = broker.subscriber("dynamic")
    subscriber(handler_method)
    broker.setup_subscriber(subscriber)
    await subscriber.start()
    await subscriber.close()


async def main() -> None:
    broker = NatsBroker()
    async with TestNatsBroker(broker) as br:
        await start_stop(br)
        await broker.publish(subject="dynamic", message=None)

asyncio.run(main())

Environment
FastStream 0.5.34 with CPython 3.12.1 on Windows
Same on Linux.

Thanks for your work on this awesome project! :)

@saschnet saschnet added the bug Something isn't working label Jan 24, 2025
@Lancetnik Lancetnik moved this to Backlog in FastStream Jan 28, 2025
@Lancetnik
Copy link
Member

Thank you for the report! I know about Issue and planning to fix it in 0.6.*
Unfortunately, such changes requires refactoring deep inside the project core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants