question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PendingMessagesQueue growth is unbound

See original GitHub issue

I am running MQTT server in a docker container, and i get strange behaviour where the amount of memory bloats into gigabytes.

image image

The system is Producer -> Server -> MultipleConsumers The producer also uses MQTTnet, and sends ~100 messages per second, QOS 0 The consumers use MQTTnet too. they often disconnect without closing connection properly. The behaviour only occurs if the clients connect, and then disconnect. If the server is started, the producer is connected and producing messages but no client connect, then memory use stays very low (<100MB) It is not obvious to me why this is happening at this point. I could not reproduce it previously on my local machine in VS debugger, but I will try again soon.

Kubernetes Version - 1.7 .Net SDK / Runtime :

  • 2.0
  • 2.1 preview 2

There is a related issue - https://github.com/dotnet/coreclr/issues/14991#issuecomment-348428003 However I made sure that this isn’t the issue appearing here by running GC.Collect() every second - the issue still persists.

Server Code

public static readonly DateTime StartTimeUTC = DateTime.UtcNow;

static void Main(string[] args)
{
   Console.WriteLine("Server Started!");
   Task.Run(async () => await StartServer()).Wait();
}

private static async Task StartServer()
{
	var optionsBuilder = new MqttServerOptionsBuilder()
		.WithConnectionBacklog(100)
		.WithDefaultEndpointPort(1883);
	var mqttServer = new MqttFactory().CreateMqttServer();
	await mqttServer.StartAsync(optionsBuilder.Build());
	var ct = new CancellationTokenSource();
	var heartbeatTask = Task.Run(async () => await ServerHeartbeat(ct.Token, mqttServer)); 
  
	Console.WriteLine("Type 'quit' to exit");

	string input = string.Empty; 
	while (true)
	{
		//Docker has a habit of sending random shit into CMD
		char c = (char)Console.Read();
		input +=  c; 

	   if (input.Contains("quit")) 
		{
			Console.WriteLine("Shutting Down...");
			break;
		}
		else if (input.Length > 10)
		{
			input = input.Substring(input.Length - 3); 
		}
	}
	ct.Cancel();
	await heartbeatTask;
	await mqttServer.StopAsync();
}

private static async Task ServerHeartbeat(CancellationToken token, IMqttServer server)
{
  long heartbeat =0;
  while (token.IsCancellationRequested == false)
  {
	var message = new MqttApplicationMessageBuilder()
	 .WithTopic("$SYS/broker/uptime")
	 .WithPayload($"{DateTime.UtcNow - StartTimeUTC}")
	 .WithAtMostOnceQoS()
	 .WithRetainFlag(false)
	 .Build();
	await server.PublishAsync(message);

	message = new MqttApplicationMessageBuilder()
	 .WithTopic("$SYS/broker/time")
	 .WithPayload($"{DateTime.UtcNow}")
	 .WithAtMostOnceQoS()
	 .WithRetainFlag(false)
	 .Build();
	await server.PublishAsync(message);
	await Task.Delay(1000);
}

Am I doing something dumb? I will update the ticket as I continue testing.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
VLorzcommented, May 2, 2018

Hi Christian, same issue with version 2.7.5-rc1, yet it took longer than with previous version. Regards, Victor

1reaction
chkr1011commented, Apr 23, 2018

Hi, thank you for sharing this issue and providing details. I will release a new RC soon with several perforrmance optimizations including some memory related optimizations. Best regards Christian

Read more comments on GitHub >

github_iconTop Results From Across the Web

asyncio.Queue.put never yields if the queue is unbounded
I have attached a file with a minimal reproducer. It creates an unbounded queue. A 'publish' task calls `queue.put` from an infinite sequence....
Read more >
The Big Little Guide to Message Queues
Message queues are one of these things that sound great in theory but IME has simply been a way of adding more failure...
Read more >
Redis Streams and Message Queues
It is a bad idea to have a stream that grows forever. As everything in Redis is stored in memory, a data structure...
Read more >
Backpressure and Unbounded Queues #19 - dotnet/reactive
The problems of backpressure (fast producer, slow consumer) and unbounded queues in native operators (e.g., Zip, GroupBy, Merge) appear to be ...
Read more >
The Stuff That Every Developer Should Know About ...
The message queue sits between producers and consumers, making their communication and existence decoupled. When a producer wants to communicate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found