nats-io / nats.java

Java client for NATS
Apache License 2.0
563 stars 154 forks source link

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

Closed hjk235456 closed 2 months ago

hjk235456 commented 4 months ago

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.
scottf commented 3 months ago

@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 commented 2 months ago

This is fixed by a bug fix with Poison Pill