-
Notifications
You must be signed in to change notification settings - Fork 13
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
Producer Needs Safely Closed #121
Comments
Thank you for reporting the issue @garvenlee |
HI @garvenlee can you also copy the code here? thanks! |
from asyncio import Future
from rstream import RouteType, SuperStreamProducer, ConfirmationStatus
from rstream.amqp import _MessageProtocol
from google.protobuf.message import Message
from chat.proto.services.push.push_pb2 import PubEventToUser
SUPER_STREAM = "message_stream"
MESSAGES = 10000000
class PubEvent(_MessageProtocol):
__slots__ = "data"
def __init__(self, data: Message):
self.data = data
def __bytes__(self):
return self.data.SerializeToString()
async def route_extractor(message: PubEvent):
return str(message.data.uid)
def cb(confirmation: ConfirmationStatus):
if not confirmation.is_confirmed:
print(confirmation)
async def publish():
async def on_closed(exc):
print("triggered on_closed.", exc)
nonlocal needs_pause
if not needs_pause:
needs_pause = True
try:
await super_stream_producer.close()
except Exception as e:
print(e) # Timeout
finally:
closed_waiter.set_result(None)
needs_pause = False
super_stream_producer = SuperStreamProducer(
"localhost",
username="guest",
password="guest",
routing_extractor=route_extractor,
routing=RouteType.Hash,
super_stream=SUPER_STREAM,
connection_closed_handler=on_closed,
)
await super_stream_producer.start()
closed_waiter = Future()
for i in range(MESSAGES):
if needs_pause:
break
await super_stream_producer.send(
PubEvent(
PubEventToUser(channel_number=i, evt_data=bytes(f"hello, {i}", "ascii"))
),
on_publish_confirm=cb,
)
await closed_waiter
await Future()
if __name__ == "__main__":
# import uvloop
# uvloop.install()
import asyncio
asyncio.run(publish())
|
We are working on it.
We don't want to provide the auto-reconnect feature on the |
Additionally, |
Another: In |
HI @garvenlee yes thanks to have noticed the issue. Yeah I'm realizing the bug and I'm staring working on it here #131 with some other improvements |
If the RabbitMQ broker goes down, rstream library will trigger connection_closed callback, but
producer.close
will still calldelete_publisher
synchronously, thereby suppressing blocking/timeout and preventing the internal state from being cleaned up. This is what happens under theasyncio
standard EventLoop, if you useuvloop
, it will directly raise theRuntimeError
inwrite_frame
, which is not asocket.OSError
The text was updated successfully, but these errors were encountered: