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

bug: NodeJS does not exit after node.stop() is called #2210

Open
dbu9 opened this issue Jan 17, 2025 · 2 comments
Open

bug: NodeJS does not exit after node.stop() is called #2210

dbu9 opened this issue Jan 17, 2025 · 2 comments
Labels

Comments

@dbu9
Copy link

dbu9 commented Jan 17, 2025

Run

import { createLightNode } from "@waku/sdk";

async function main() {
	
	// Create and start a Light Node
	const node = await createLightNode({ defaultBootstrap: true });
	await node.start();
	console.log("Node started");
	
	// Use the stop() function to stop a running node
	await node.stop();
	await node.libp2p.stop();
	console.log("Stopped");
	
}

main();

Output:

Ignore WebSocket connection failures
Waku tries to discover peers and some of them are expected to fail
Node started
Stopped

Image

@chair28980 chair28980 added this to Waku Jan 17, 2025
@weboko weboko moved this to Triage in Waku Jan 17, 2025
@weboko weboko changed the title NodeJS does not exit after node.stop() is called bug: NodeJS does not exit after node.stop() is called Jan 17, 2025
@weboko
Copy link
Collaborator

weboko commented Jan 17, 2025

Thank you for reporting it @dbu9!

Expected behavior in that case is that NodeJS program should exit once Event loop is empty.
Actual behavior is that js-waku seems to retain some event listeners and/or timers thus preventing NodeJS from exit.

Mitigation I can think of right now is to use process.exit(0); at the end of your script to exit from the process otherwise you can safely assume js-waku is kinda stopped and won't consume a lot of resources even though there are some pending timers / events left.

Things that we need to investigate and potentially re-work:

  • centralize scheduling or events and timers within js-waku codebase;
  • make sure to dispose them upon waku.stop();
  • see if it solves the problem;

@weboko weboko added the NodeJS label Jan 17, 2025
@weboko weboko moved this from Triage to Icebox in Waku Jan 17, 2025
@weboko
Copy link
Collaborator

weboko commented Jan 17, 2025

Ice boxing for now as js-waku optimizes for Browser and NodeJS is descoped for next period for now.
For NodeJS you can try using nwaku bindings or REST API.

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

No branches or pull requests

2 participants