Currently, whenever the server is stopped, the server's goroutine will
panic because the channel on which it needs to send its return value is
closed before the value is read/sent.
This commit fixes the issue by inverting the closing of the channel and
letting the sender, i.e. the server's goroutine, do the closing of the
channel. This ensures that the channel is only closed after the return
value has been sent. On the receiving side, the channel is drained to
ensure that the goroutine has finished before moving on. Note that this
draining will not block because either it will receive an error from the
server or it will receive nothing because the channel was closed.
Currently, whenever the server is stopped, the server's goroutine will panic because the channel on which it needs to send its return value is closed before the value is read/sent.
This commit fixes the issue by inverting the closing of the channel and letting the sender, i.e. the server's goroutine, do the closing of the channel. This ensures that the channel is only closed after the return value has been sent. On the receiving side, the channel is drained to ensure that the goroutine has finished before moving on. Note that this draining will not block because either it will receive an error from the server or it will receive nothing because the channel was closed.
Fixes: #37
Signed-off-by: Lucas Servén Marín lserven@gmail.com