Skip to content

Infinite reconnections (with error) when authentication fails on Java client #8922

Closed as not planned

Description

@fmiguelez

Describe the bug
Connection layer of Java client keeps on trying (and failing to) reconnect to broker when access token used to authenticate expires.

It seems that connection pool handles connections transparently in the background even if all consumers/readers are closed.

To reproduce it create a consumer with a Pulsar with security (JWT auth) enabled. Use a short-lived token (a few minutes). Once token has expired now and then connection times out and pool tries to reconnect it (even if no consumers/readers are present). Then we will see periodically in log these entries:

2020-12-11 14:25:38.342 INFO 29332 --- [sar-timer-139-1] o.a.p.client.impl.ConnectionHandler : [persistent://dbus/test/dummy-objects] [reader-0f59ce70b0] Reconnecting after connection was closed
2020-12-11 14:25:38.344 INFO 29332 --- [client-io-136-1] o.a.pulsar.client.impl.ConnectionPool : [[id: 0xf03136ce, L:/127.0.0.1:52383 - R:localhost/127.0.0.1:6650]] Connected to server
2020-12-11 14:25:38.348 WARN 29332 --- [client-io-136-1] org.apache.pulsar.client.impl.ClientCnx : [id: 0xf03136ce, L:/127.0.0.1:52383 - R:localhost/127.0.0.1:6650] Received error from server: Unable to authenticate
2020-12-11 14:25:38.348 WARN 29332 --- [client-io-136-1] o.a.pulsar.client.impl.ConnectionPool : [[id: 0xf03136ce, L:/127.0.0.1:52383 - R:localhost/127.0.0.1:6650]] Connection handshake failed: org.apache.pulsar.client.api.PulsarClientException$AuthenticationException: Unable to authenticate
2020-12-11 14:25:38.348 WARN 29332 --- [client-io-136-1] o.a.p.client.impl.ConnectionHandler : [persistent://dbus/test/dummy-objects] [reader-0f59ce70b0] Error connecting to broker: org.apache.pulsar.client.api.PulsarClientException$AuthenticationException: Unable to authenticate
2020-12-11 14:25:38.348 WARN 29332 --- [client-io-136-1] o.a.p.client.impl.ConnectionHandler : [persistent://dbus/test/dummy-objects] [reader-0f59ce70b0] Could not get connection to broker: org.apache.pulsar.client.api.PulsarClientException$AuthenticationException: Unable to authenticate -- Will try again in 57.76 s
2020-12-11 14:25:38.348 ERROR 29332 --- [client-io-136-1] org.apache.pulsar.client.impl.ClientCnx : [id: 0xf03136ce, L:/127.0.0.1:52383 ! R:localhost/127.0.0.1:6650] Failed to authenticate the client
2020-12-11 14:25:38.348 WARN 29332 --- [client-io-136-1] org.apache.pulsar.client.impl.ClientCnx : [id: 0xf03136ce, L:/127.0.0.1:52383 ! R:localhost/127.0.0.1:6650] Received unknown request id from server: -1
2020-12-11 14:25:38.348 INFO 29332 --- [client-io-136-1] org.apache.pulsar.client.impl.ClientCnx : [id: 0xf03136ce, L:/127.0.0.1:52383 ! R:localhost/127.0.0.1:6650] Disconnected

To Reproduce
Enable JWT based authentication and issue a short-lived token. Publish and consume some messages using that token. Wait a few minutes until token expires.

Expected behavior
Connection pool should not try to reconnect (or at least retry only a few times) when authentication fails.

Screenshots

Desktop (please complete the following information):

  • Windows (Docker Desktop)

Additional context

Activity

  1. added
    type/bug
    on Dec 11, 2020
  2. frankjkelly commented on May 26, 2021

    @frankjkelly
    Contributor

    Any chance this is related to #7927 - at least insofar as the reconnections bit?

  3. tisonkun commented on Dec 9, 2022

    @tisonkun
    Member

    Closed as stale. Please create a new issue if it's still relevant to the maintained versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staletype/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions