nats.java
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.
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.
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.
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
- Set maxReconnects in the connection parameters to -1.
- The NATS server is not started.
@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.
This is fixed by a bug fix with Poison Pill