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

Rstream does not close a connection after 2 heartbeat intervals #201

Open
nesb1 opened this issue Sep 2, 2024 · 2 comments
Open

Rstream does not close a connection after 2 heartbeat intervals #201

nesb1 opened this issue Sep 2, 2024 · 2 comments

Comments

@nesb1
Copy link
Contributor

nesb1 commented Sep 2, 2024

In AMQP specification stated about actions on missing heartbeats:

"If a peer detects no incoming
traffic (i.e. received octets) for two heartbeat intervals or longer, it should close the connection without
following the Connection.Close/Close-Ok handshaking, and log an error."

In a code I found this situation handler

async def _heartbeat_sender(self) -> None:
        if self._heartbeat == 0:
            return

        while True:
            await self.send_frame(schema.Heartbeat())
            await asyncio.sleep(self._heartbeat)

            if time.monotonic() - self._last_heartbeat > self._heartbeat * 2:
                logger.warning("Heartbeats from server missing") # no connection close, only log

If I understood correctly, then the server should close the connection at this point, why does it not do this?

I have a guess as to why this is so. If the tcp connection is dead, then the rabbitmq server should also detect the absence of heartbeats and close the connection, right?

@Gsantomaggio
Copy link
Member

Gsantomaggio commented Sep 3, 2024

Thank you, @nesb1, for reporting the issue.
The client should close the connection after not receive X heartbeats.
We have to analyse it. We can't guarantee an ETA since we are busy on something else at the moment.

@DanielePalaia
Copy link
Collaborator

DanielePalaia commented Oct 3, 2024

Hi @nesb1 I think we can close the client at that point, maybe after two heartbeats get missed from the server like the other clients are doing. The fact is that we need to find a way to be able to notify the caller in order allow proper cleanup (for example closing the producer) or allow other final operations to be finalized. The issue is that at the moment the connection_closed_handler is managed differently from Producer and Consumer. In case of Consumer should be implemented and passed by the caller while in case of Producer is the one defined in producer.py (_on_connection_closed). This diversion of flow at moment can create some issue. This is maybe not a top priority at the moment for the library, but if you like to improve this heartbeat management feel free to open a PR!

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

No branches or pull requests

3 participants