Skip to content

Nats Consumer is not reconnecting if it loses connectivity to NATS server #7

@dev360

Description

@dev360

What version of Django Nats Consumers are you using?
1.2

What version of Django are you using?

For example: 4.2

Did you checked changelog/commit history, if the bug is not already fixed?

Yes

Did you searched other issues, if the bug is not already fixed?

Yes

Repository with reproduced bug

Can be reproduced in existing docker-compose.yml if you shut down the nats server.

Describe your issue
This error occures when the nats server is shut down. The nats_consumer client should know how to reconnect or exit the main loop.

ERROR:nats.aio.client:nats: encountered error
Traceback (most recent call last):
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/nats/aio/client.py", line 1353, in _select_next_server
    await self._transport.connect(
  File "/opt/pysetup/.venv/lib/python3.10/site-packages/nats/aio/transport.py", line 121, in connect
    r, w = await asyncio.wait_for(
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/asyncio/streams.py", line 48, in open_connection
    transport, _ = await loop.create_connection(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1036, in create_connection
    infos = await self._ensure_resolved(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1418, in _ensure_resolved
    return await loop.getaddrinfo(host, port, family=family, type=type,
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/socket.py", line 967, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
^CERROR:nats_consumer.consumer:Error unsubscribing from <nats.js.client.JetStreamContext.PushSubscription object at 0xffffa6db24a0>: nats: connection closed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions