ssbc / ssb-server

The gossip and replication server for Secure Scuttlebutt - a distributed social network
1.69k stars 164 forks source link

Graceful termination of the server #572

Open staltz opened 5 years ago

staltz commented 5 years ago

Problem

sbot already has close() function, which will call secret-stack's close and tear down peer connections. But, depending on the set of plugins you use, sbot.close() will either terminate (and its parent node.js process will end), or will hang indefinitely.

For instance, if you use scuttlebot/plugins/local, then sbot.close() will leave the node.js process hanging, supposedly because the LAN broadcast stream is still open. But if you disable that plugin and use a few of the canonical plugins, then sbot.close() might correctly terminate the node.js process.

Motivation

To run sbot on mobile, it runs in node.js as a thread, and there is no way of killing a thread. Sometimes we require being able to control the beginning and end of that thread, e.g. for restarting purposes. Overall, having sbot.close() consistently get rid of all the resources it uses will help us to have more flexibility in implementations and avoid the more aggressive process.exit().

Proposed solution

My first guess is to change secret-stack so that close() will also attempt to call p.close() for each plugin p. Plugins then should have good enough implementations and provide a close method in their manifest whenever applicable. This is not scuttlebot-specific, it's secret-stack, but at least scuttlebot/plugins/local should be improved.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.