Commit 0f63e8d7 authored by shammash's avatar shammash

fix exit when half connected

Signed-off-by: shammash's avatarshammash <>
parent 3bb444e4
......@@ -190,10 +190,17 @@ func (notifier *IRCNotifier) Run() {
if notifier.Client.Connected() {
log.Printf("IRC client connected, quitting")
notifier.Client.Quit("see ya")
// Wait for disconnect to complete
if notifier.sessionUp {
log.Printf("Session is up, wait for IRC disconnect to complete")
select {
case <-notifier.sessionDownSignal:
case <-time.After(notifier.Client.Config().Timeout):
log.Printf("Timeout while waiting for IRC disconnect to complete, stopping anyway")
notifier.StoppedRunning <- true
......@@ -652,3 +652,55 @@ func TestGhostAndIdentify(t *testing.T) {
t.Error("Ghosting did not happen correctly. Received commands:\n", strings.Join(server.Log, "\n"))
func TestStopRunningWhenHalfConnected(t *testing.T) {
server, port := makeTestServer(t)
config := makeTestIRCConfig(port)
notifier, _ := makeTestNotifier(t, config)
var testStep, holdQuitWait sync.WaitGroup
// Send a StopRunning request while the client is connected but the
// session is not up
holdUser := func(conn *bufio.ReadWriter, line *irc.Line) error {
log.Printf("=Server= NOT completing session")
return nil
server.SetHandler("USER", holdUser)
// Ignore quit, but wait for it to have deterministic test commands
holdQuit := func(conn *bufio.ReadWriter, line *irc.Line) error {
log.Printf("=Server= Ignoring quit")
return nil
server.SetHandler("QUIT", holdQuit)
go notifier.Run()
notifier.StopRunning <- true
// Client has left, cleanup the server side before stopping
expectedCommands := []string{
"NICK foo",
"USER foo 12 * :",
"QUIT :see ya",
if !reflect.DeepEqual(expectedCommands, server.Log) {
t.Error("Alert not sent correctly. Received commands:\n", strings.Join(server.Log, "\n"))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment