Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate channel leak in the CachingConnectionFactory when connection is closed from the broker #2715

Closed
artembilan opened this issue May 20, 2024 Discussed in #2637 · 2 comments

Comments

@artembilan
Copy link
Member

Discussed in #2637

Originally posted by arn-rio February 26, 2024
Hello,

We experienced some issues using correlated Rabbit confirm publishers.
Rabbit server was unstable for a while. Once restored, we were unable to publish new confirmed messages to it (the max number of channel on connection was reached and the existing channels were ignored).
The solution was to restart the service (we could force close the connection : but it only worked when channel cache size wasn't set in CachingConnectionFactory)

We investigated and found that :

  • when a message is published but not confirmed, assigned channel is not used for an other message. (see spring amqp documentation )
  • so CachingConnectionFactory creates new channels, and then number of channel in connection increases.
  • Finally, there is no channel available on the connection : max number of channels reached
    when a new channelCacheSize and channelCheckoutTimeout are set in CachingConnectionFactory, we got 'No available channels' error, otherwise, 'The channelMax limit is reached'.

We call RabbitTemplate.getUnconfirmed() in a periodic task : the correlation data are removed, but unfortunatly, the related channel is not freed and not available for new publish.

You can observe and reproduce the issue as follows :

  • a periodic task that publishes a confirmed message on Rabbit every 20 ms
  • a cron job that calls RabbitTemplate.getUnconfirmed()
  • on a local Rabbit server, block then unblock connection by updating memory watermark
	//block connections 
	rabbitmqctl set_vm_memory_high_watermark <low threshold>
	//unblock
	rabbitmqctl set_vm_memory_high_watermark <high threshold>

Is there a better way to manage not confirmed messages? How can we free the channels when confirmation is not received before a timeout?

Thanks

@artembilan artembilan added this to the 3.1.5 milestone May 20, 2024
artembilan added a commit that referenced this issue May 20, 2024
Fixes: #2715

When connection is closed from the broker, there are some channels leak into a cache after reconnection
@andrei-ivanov
Copy link

what's a borker? 😁

@artembilan artembilan changed the title Mitigate channel leak in the CachingConnectionFactory when connection is closed from the borker Mitigate channel leak in the CachingConnectionFactory when connection is closed from the broker May 20, 2024
@artembilan
Copy link
Member Author

That typo has been fixed.
Thanks

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

No branches or pull requests

3 participants