perlin-network / noise

A decentralized P2P networking stack written in Go.
https://godoc.org/github.com/perlin-network/noise
MIT License
1.78k stars 213 forks source link

Node stops answering Pings when put in background #282

Open lrahmani opened 4 years ago

lrahmani commented 4 years ago

Issue

When a node is sent to background (^z + bg) it stops answering pings from other nodes. The issue is also present when the node is a run as a background process using &. I didn't investigate further issues caused by running the node in the background other than not answering pings (for e.g. handling incoming message).

Expected behavior

I expect the node to have similar behavior when run/put in background as when it is running in foreground.

How to reproduce it

This behavior is entirely reproducible using the chat example running on a ubuntu:18.4-based docker image with GNU bash-4.4.20(1)-release.

  1. get the chat example go get -d -v github.com/perlin-network/noise/cmd/chat
  2. run a first instance of the chat example go run github.com/perlin-network/noise/cmd/chat -p 9000
  3. on a separate terminal, run a second instance of the chat example to join the first one go run github.com/perlin-network/noise/cmd/chat -p 9001 127.0.0.1:9000. Both nodes should learn about each other
  4. send the first instance (listening on port 9000) to the background by pressing Ctrl+Z and then executing command bg
  5. run a thrid instance of the chat example with first instance's address as bootstrap node go run github.com/perlin-network/noise/cmd/chat -p 9003 127.0.0.1:9000. This node will shortly report that it cannot ping the bootstrap node.

Suggestions

From jobs output, it seems that the node process doesn't switch to be Running when executing bg after being stopped by Ctrl+Z. The issue could be related to the input goroutine not having access to stdin, unfortunately I am very new to go and cannot provide suggestions about goroutine interactions with the shell.