question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nats.aio.errors.NatsError: nats: empty response from server when expecting INFO message

See original GitHub issue

Hi

I am trying to understand why my nats setup is not working like it should.

Setup

NATS server

I am using the helm chart with image: nats:2.1.7-alpine3.11

values.yaml:

nats:
  image: nats:2.1.7-alpine3.11
  pullPolicy: IfNotPresent

  externalAccess: false
  advertise: true

  serviceAccount: "nats-server"

  connectRetries: 30

  pingInterval:

  limits:
    maxConnections:
    maxSubscriptions:
    maxControlLine: 512
    maxPayload: "1000000000"

    writeDeadline: "2s"
    maxPending:
    maxPings:
    lameDuckDuration:

  logging:
    debug: true
    trace: true
    logtime:
    connectErrorReports:
    reconnectErrorReports:

  tls:
    url: <DUMMYDATA>
    issuerName: letsencrypt-prod
    secret:
      name: nats-client-tls
    cert: "tls.crt"
    key: "tls.key"

nameOverride: ""
imagePullSecrets: []

securityContext: null
affinity: {}
podAnnotations: {}

nodeSelector:
  doks.digitalocean.com/node-pool: staging

cluster:
  enabled: true
  replicas: 3

leafnodes:
  enabled: false

gateway:
  enabled: false
  name: 'default'

bootconfig:
  image: connecteverything/nats-boot-config:0.5.2
  pullPolicy: IfNotPresent

reloader:
  enabled: true
  image: connecteverything/nats-server-config-reloader:0.6.0
  pullPolicy: IfNotPresent

exporter:
  enabled: true
  image: synadia/prometheus-nats-exporter:0.5.0
  pullPolicy: IfNotPresent

auth:
  enabled: true

  operatorjwt:
    configMap:
      name: operator-jwt-nats
      key: operator.jwt
      data: "DUMMYDATA"

  systemAccount: DUMMYDATA

  resolver:
    type: URL
    type: URL
    url: "http://nats-account-server:9090/jwt/v1/accounts/"

NATS is hosted on DigitalOcean and can be accessed via a LoadBalancer.

Nats client

requirements.txt

asyncio-nats-client[nkeys]==0.11.2
fastapi==0.61.0
#! /usr/bin/python

import asyncio
import logging
import ssl
from typing import Any

from fastapi import FastAPI
from nats.aio.client import Client as NATS
from pydantic import BaseModel

HOST_NATS = ""
NATS_CREDENTIALS_FILE = ""


class NatsClient(BaseModel):
    nc: Any = None

    @property
    def connected(self) -> bool:
        return self.nc.is_connected

    async def error_cb(self, e):
        logging.error("NATS Error:", e)

    async def closed_cb(self):
        logging.error("NATS CLOSED")

    async def reconnected_cb(self):
        logging.error("NATS RECONNECTED")

    async def setup(self) -> None:
        self.nc: NATS = NATS()

        context = ssl.create_default_context()
        await self.nc.connect(
            HOST_NATS,
            allow_reconnect=True,
            tls=context,
            user_credentials=NATS_CREDENTIALS_FILE,
            error_cb=self.error_cb,
            closed_cb=self.closed_cb,
            reconnected_cb=self.reconnected_cb,
            verbose=True,
            ping_interval=5,
        )

    async def teardown(self):

        await self.nc.close()


def create_app() -> "FastAPI":
    app = FastAPI()

    app.state.nats_client = NatsClient()

    @app.on_event("startup")
    async def setup() -> None:
        app.state.loop = asyncio.get_event_loop()
        await app.state.nats_client.setup()

    @app.on_event("shutdown")
    async def teardown() -> None:
        await app.state.nats_client.teardown()


app = create_app()

Problem

The problem I am having is that nats clients are not reconnecting properly and outputting these errors.

root 2020-09-26 13:31:43 ERROR (__init__-error_cb:23) >> NATS ERROR: 
root 2020-09-26 13:31:43 ERROR (__init__-error_cb:23) >> NATS ERROR: 
root 2020-09-26 13:31:43 ERROR (__init__-error_cb:23) >> NATS ERROR: nats: empty response from server when expecting INFO message
root 2020-09-26 13:31:43 ERROR (__init__-error_cb:23) >> NATS ERROR: nats: empty response from server when expecting INFO message
root 2020-09-26 13:31:43 ERROR (__init__-closed_cb:26) >> NATS CLOSED
root 2020-09-26 13:31:43 ERROR (__init__-closed_cb:26) >> NATS CLOSED

Is there something I do wrong here?

Greetings

Sebastiaan

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sevahocommented, Sep 29, 2020

@wallyqs thank you very much, I’ve upgraded the server and updated the clients. I’ll wait until end of week to close this issue if you don’t mind just to be sure it works as expected.

greetings

sevaho

0reactions
sevahocommented, Oct 5, 2020

Hi @wallyqs I don’t have the problem anymore so it looks like it worked 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Library reconnects don't work · Issue #66 · nats-io/nats.py
error (NatsError('nats: empty response from server when expecting INFO message',),) {} reconnect () {} error (<class 'nats.aio.errors.
Read more >
python nats connection error when running from a class
You are passing self.CONNECTTIMEOUT as a positional parameter to Client.connect where it expects a reference for its io_loop parameter.
Read more >
Modules - NATS Docs
If a callback isn't provided, messages can be retrieved via an asynchronous iterator on the returned subscription object. Return type. Subscription. asyncnats.
Read more >
Developing a Client - NATS Docs
This guide provides you with considerations for developing NATS clients, ... Periodically, the NATS server pings each subscriber, expecting a reply.
Read more >
Authentication - Panini
NATS offers several authentication strategies, we suggest you ... raise NatsError("nats: " + err_msg.rstrip('\r\n')) nats.aio.errors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found