mqtt.js client causes event loop to stop

Open
#1,031 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, nodejs
Domain
desktop

Research direction

Start by reproducing the issue from the nodegui-starter Quick Start setup on Windows with NodeGUI 0.62.0, then compare the label-update loop with and without the mqtt.js connection. The fix is complete when connecting to the MQTT server no longer stops the loop or freezes the QWindow.

Written by the indexing model from the issue text.

Description

Describe the bug
As soon as I connect to an MQTT broker, the event loop stops running and/or becomes very unpredictable.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the nodegui-starter as described in the Quick Start Guide
  2. npm install @nodegui/nodegui@latest --save
  3. Add a loop to update one of the labels every second
async function loop() {
	while(true) {
		const timestamp = Math.floor(+new Date() / 1000);
		label.setText( `Timestamp: ${timestamp.toString()}` );
		await new Promise(resolve => setTimeout(resolve, 1000));
	}
}
loop();
  1. npm start
  2. Everything works as expected. Woo!
  3. install mqtt module, connect to MQTT server
import * as mqtt from 'mqtt';
mqtt.connect('mqtt://localhost:1883');
  1. Add a button listener, just in case this is related to #864 button.addEventListener('clicked',(checked)=>console.log("clicked"));
  2. The loop executes once, but then gets stuck. Even if I click the button.

Expected behavior
The label should continue to be updated every second, even with a MQTT client present.

Desktop (please complete the following information):

  • OS: Windows
  • NodeGUI version: 0.62.0
  • OS Version: Windows 11

Additional Context
I've tried various other ways of pausing execution, including not using Promises or setTimeout, but this usually ends up freezing the QWindow altogether, resulting in a white, empty window.

Dominant language
C++
Stars
9.2k
Forks
315
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodegui/nodegui

All issues in nodegui/nodegui

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.