imap: start reconnect when initial connect fails
Start the reconnect cycle when the initial connect fails. Make the connection observer send a connection error when the imap client is nil. Signed-off-by: Koni Marti <koni.marti@gmail.com>
This commit is contained in:
parent
8ed9ae7f0a
commit
48e01bd51f
|
@ -191,6 +191,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
w.autoReconnect = true
|
w.autoReconnect = true
|
||||||
c, err := w.connect()
|
c, err := w.connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
checkConn(0)
|
||||||
reterr = err
|
reterr = err
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -335,13 +336,20 @@ func (w *IMAPWorker) exponentialBackoff() (time.Duration, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *IMAPWorker) startConnectionObserver() {
|
func (w *IMAPWorker) startConnectionObserver() {
|
||||||
|
emitConnErr := func(errMsg string) {
|
||||||
|
w.worker.PostMessage(&types.ConnError{
|
||||||
|
Error: fmt.Errorf(errMsg),
|
||||||
|
}, nil)
|
||||||
|
}
|
||||||
|
if w.client == nil {
|
||||||
|
emitConnErr("imap client not connected")
|
||||||
|
return
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-w.client.LoggedOut():
|
case <-w.client.LoggedOut():
|
||||||
if w.autoReconnect {
|
if w.autoReconnect {
|
||||||
w.worker.PostMessage(&types.ConnError{
|
emitConnErr("imap: logged out")
|
||||||
Error: fmt.Errorf("imap: logged out"),
|
|
||||||
}, nil)
|
|
||||||
}
|
}
|
||||||
case <-w.done:
|
case <-w.done:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue