From 8e67699fe4c3e78aa5b372c2ded434409f580615 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 4 Mar 2020 18:16:26 +0100 Subject: [PATCH] Better practices --- account.go | 2 +- connector/external/external.go | 1 + connector/mattermost/mattermost.go | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/account.go b/account.go index f0954e8..e6a2e3d 100644 --- a/account.go +++ b/account.go @@ -136,7 +136,7 @@ func CloseAllAccountsForShutdown() { for _, accl := range registeredAccounts { for _, acct := range accl { - log.Printf("Closing %#v", acct) + log.Printf("Closing %s %s (%s)", acct.MatrixUser, acct.AccountName, acct.Protocol) acct.Conn.Close() } } diff --git a/connector/external/external.go b/connector/external/external.go index 9896750..553c657 100644 --- a/connector/external/external.go +++ b/connector/external/external.go @@ -338,6 +338,7 @@ func (ext *External) Close() { ext.proc.Process.Kill() }() ext.proc.Wait() + log.Info("External process exited") ext.proc = nil ext.recvPipe = nil diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go index ea49fd2..9410126 100644 --- a/connector/mattermost/mattermost.go +++ b/connector/mattermost/mattermost.go @@ -31,7 +31,7 @@ type Mattermost struct { initial_backlog int // How many previous messages (maximum) to load when first joining a channel conn *matterclient.MMClient - handlerStopChan chan bool + handlerStopChan chan struct{} caches mmCaches } @@ -59,7 +59,7 @@ func (mm *Mattermost) Configure(c Configuration) error { } // Reinitialize shared data structures - mm.handlerStopChan = make(chan bool, 1) + mm.handlerStopChan = make(chan struct{}) mm.caches.mmusers = make(map[string]string) mm.caches.sentjoined = make(map[string]bool) @@ -323,7 +323,7 @@ func (mm *Mattermost) Close() { mm.conn.WsQuit = true } if mm.handlerStopChan != nil { - mm.handlerStopChan <- true + close(mm.handlerStopChan) mm.handlerStopChan = nil } } @@ -484,7 +484,7 @@ func (mm *Mattermost) processBacklog(ch *model.Channel, backlog *model.PostList) } } -func (mm *Mattermost) handleLoop(msgCh chan *matterclient.Message, quitCh chan bool) { +func (mm *Mattermost) handleLoop(msgCh chan *matterclient.Message, quitCh chan struct{}) { for { select { case <-quitCh: