Flutter app for Linux get 100% of CPU utilization

Hello..

I have developed a flutter application that uses StreamController to send messages to other class which is listening to them.

The definition is:

final StreamController<ReceivedMqttMessage> _messageController =

StreamController<ReceivedMqttMessage>.broadcast();

Stream<ReceivedMqttMessage> get messages => _messageController.stream;

When I need to send a message, I run this code:

_messageController.add(ReceivedMqttMessage(msg.topic!, payload));

After several calls, suddenly, CPU utilization grows up to 100%.

I cannot debug such a fact because all occurs asynchronously. Is there a way to use another mecanism to send message to other class?

When CPU is at 100% I cannot even use CPU profiler because application get stuck when that happens.

I use VSCode to develop.

Thanks

Jaime

You probably have cyclic event emissions which triggers events to be fired non stop in a cycle. Put some loggs, please. Also dart dev tools can help debug performance issues. Put a limit queue on the events as well as you might get spammed from mqtt