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

mqtt.js client causes event loop to stop #1031

Open
jeffcrouse opened this issue Oct 23, 2023 · 2 comments
Open

mqtt.js client causes event loop to stop #1031

jeffcrouse opened this issue Oct 23, 2023 · 2 comments

Comments

@jeffcrouse
Copy link

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 Promises don't resolve until a QT event is raised. #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.

@jeffcrouse jeffcrouse changed the title Incompatible with mqtt.js mqtt.js client causes event loop to stop Oct 23, 2023
@sedwards2009
Copy link
Collaborator

Do you know if mqtt.js works ok in a pure nodejs context? Do timers etc fire correctly when using mqtt.js from node? Can we be sure that mqtt.js is actually returning to the event loop and not spinning some how?

@jeffcrouse
Copy link
Author

@sedwards2009 I have used mqtt.js in nodejs for weeks now on my current project with no unexpected results. If there are particular tests that would give you more specific information, I'd be happy to do them.

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

No branches or pull requests

2 participants