Summary
An unexpected disconnection issue with stomp.Connection(timeout=5), where connections terminate after 5 seconds despite a successful initial connection, contrasting with Python socket behavior which maintains the connection post-timeout.
Problem
I'm running activeMQ in localhost, and I confirmed connection are successfully established.
If I give stomp.Connection() a timeout option as an argument, to my knowledge, timeout option would only affects only when initial connection. For example, if I use stomp.Connection(timeout=5), the expected behavior is that an exception will be thrown if connection establishment fails for 5 seconds on the first connection.
However, what I've observed is that the connection is being terminated after 5 seconds even if the connection successfully established and even when activeMQ is still available.
Code Example
If I run the code below, my expectation is that the timeout option is only applied to the initial connection, so if the connection is made within 5 seconds, the connection should be maintained. However, as you can see in terminal, the connection is disconnected after about 5 seconds. (I think the initial ‘False’ is due to the connection not being fully established yet)
import stomp
import time
conn = stomp.Connection(timeout=5)
conn.connect('localhost', 61613)
while True:
message = "Hello, world!"
print(f"Sent message: {message}")
print(conn.is_connected())
time.sleep(1)
If I write client code that does something similar with the python standard library's socket (server is on), the connection will still be maintained after the timeout has passed.
import socket
import time
def client_program():
host = "localhost"
port = 5000
client_socket = socket.socket()
client_socket.connect((host, port))
client_socket.settimeout(5)
while True:
if client_socket.fileno() == -1:
print("Connection is closed.")
break
else:
print("Connection is kept preserved.")
time.sleep(1)
if __name__ == '__main__':
client_program()
Suspected problem
There are a couple of possible problems.
- wrong code (really simple code, but where?)
- problem with ActiveMQ
- Issues with TCP keep-alive
- or Really a bug ????
Thank you for maintaining a good library. Hope for comments.

