Open
Description
What version were you using?
v2.9.6
What environment was the server running in?
docker
Is this defect reproducible?
When the nats servers becomes unavailable for a short while any pull_subscription is lost (i.e. stops receiving messages), whereas push subscribers works as expected.
Reproduce
Run the following script. Reboot the nats server. Emit messages on the queue testnats.reconnec
. Nothing is received
import asyncio
import nats
SUBJECT = "testnats.reconnect"
CLUSTER_ADDRESS = "nats://localhost:4222"
async def run(loop):
async def disconnected_cb():
print("Disconnected!")
async def reconnected_cb():
print("Reconnected!")
async def error_cb(e):
print("Error:", e)
nc = await nats.connect(
servers=[CLUSTER_ADDRESS],
error_cb=error_cb,
disconnected_cb=disconnected_cb,
reconnected_cb=reconnected_cb,
max_reconnect_attempts=-1,
)
js = nc.jetstream()
async def message_handler(msg):
subject = msg.subject
reply = msg.reply
data = msg.data.decode()
print(
"Received a message on '{subject} {reply}': {data}".format(
subject=subject, reply=reply, data=data
)
)
await msg.ack()
# await js.subscribe(SUBJECT, cb=message_handler)
subscription = await js.pull_subscribe(SUBJECT, "durable_name", "TEST_STREAM")
while True:
try:
messages = await subscription.fetch(1, 10000000)
for message in messages:
await message_handler(message)
except Exception as e:
print(e)
if __name__ == "__main__":
loop = asyncio.new_event_loop()
loop.create_task(run(loop))
loop.run_forever()
It works as expected if I uncomment the pull_subscribe logic and replace it with the commented out js.subscribe() line
Given the capability you are leveraging, describe your expectation?
Pull subscribers should reconnect after reboot
Given the expectation, what is the defect you are observing?
pull subscribers are not resubscribing