nats.java icon indicating copy to clipboard operation
nats.java copied to clipboard

When the NATS server is unavailable and the number of reconnection times is set to infinite, memory leakage occurs on the NATS client.

Open hjk235456 opened this issue 1 year ago • 1 comments

Observed behavior

When the number of reconnection times is set to -1 and the server is down, messages are stacked in the queue and will not be consumed.

1715410907127-c9l

optionBuilder .connectionName(connectName) .connectionTimeout(Duration.ofMillis(2 * CONNECTING_TIMEOUT)) .reconnectWait(Duration.ofMillis(reconnectWaitTime)) .maxReconnects(-1) .executor(es) .servers(servers) .userInfo(natsUser, natsPassword);

When the connection fails, the reconnection function is invoked. The _poison message is placed in the outgoing and reconnectOutgoing queues of NatsConnectionWriter.

1715411296188-qlm

1715411316195-i5y

Expected behavior

The number of reconnection times is set to -1, and the NATS server is not started. In this case, memory leakage does not occur.

Server and client version

jnats-2.15.6-htrunk2.jar

Host environment

No response

Steps to reproduce

  1. Set maxReconnects in the connection parameters to -1.
  2. The NATS server is not started.

hjk235456 avatar May 11 '24 07:05 hjk235456

@hjk235456 You said:

When the number of reconnection times is set to -1 and the server is down, messages are stacked in the queue and will not be consumed.

Yes message are kept in the queue based on maxMessagesInOutgoingQueue. Messages consume memory. Does the memory usage stay up after reconnect? Remember it will take some amount of time to empty the queue.

scottf avatar May 19 '24 23:05 scottf

This is fixed by a bug fix with Poison Pill

scottf avatar Jul 06 '24 16:07 scottf