From 3f91a25fbd163a5c2a0a1c4e17aeafb332585eaf Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Fri, 8 Nov 2013 03:55:18 +0000 Subject: [PATCH] attempt to handle more errors --- go/r3-netstatus/main.go | 6 +++--- go/r3-netstatus/r3xmppbot/r3xmppbot.go | 35 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index bb6ffb5..c565df2 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -121,7 +121,7 @@ func EventToXMPP(bot *r3xmppbot.XmppBot, events <- chan interface{}, xmpp_presen last_buttonpress = 0 } // Try to XMPP Ping the server and if that fails, quit XMPPBot - if bot.PingServer(2000) == false { return } + if bot.PingServer(3500) == false { return } case r3events.DoorProblemEvent: xmpp_presence_events_chan <- r3xmppbot.XMPPMsgEvent{Msg: fmt.Sprintf("Door Problem: %s. SeverityLevel: %d (%s)",event.Problem, event.Severity, time.Unix(event.Ts,0).String()), DistributeLevel: r3xmppbot.R3OnlineOnlyInfo, RememberAsStatus: false} } @@ -146,7 +146,7 @@ func RunXMPPBot(ps *pubsub.PubSub, zmqctx *zmq.Context) { } else { Syslog_.Printf("Error starting XMPP Bot: %s", xmpperr.Error()) } - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) } } @@ -194,7 +194,7 @@ func main() { go RunXMPPBot(ps, zmqctx) // --- receive and distribute events --- - ticker := time.NewTicker(time.Duration(5) * time.Minute) + ticker := time.NewTicker(time.Duration(6) * time.Minute) for { select { case e := <-zmqsub.In(): diff --git a/go/r3-netstatus/r3xmppbot/r3xmppbot.go b/go/r3-netstatus/r3xmppbot/r3xmppbot.go index 6740a84..795d7a8 100644 --- a/go/r3-netstatus/r3xmppbot/r3xmppbot.go +++ b/go/r3-netstatus/r3xmppbot/r3xmppbot.go @@ -254,9 +254,6 @@ func (botdata *XmppBot) handleIncomingMessageDialog(inmsg xmpp.Message, xmppout if inmsg.Body == nil || inmsg.GetHeader() == nil { return } - if inmsg.Type == "error" || inmsg.Error != nil { - Syslog_.Printf("XMPP Message Error: %s", inmsg.Error.Error()) - } bodytext :=inmsg.Body.Chardata if botdata.isAuthenticated(inmsg.GetHeader().From) { switch bodytext { @@ -315,16 +312,36 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm close(jabber_events) }() + var error_count int = 0 var incoming_stanza interface{} + + handleStanzaError := func() bool { + error_count++ + if error_count > 15 { + Syslog_.Println("handleIncomingXMPPStanzas: too many errors in series.. bailing out") + botdata.StopBot() + return true + } + return false + } + for incoming_stanza = range xmppin { switch stanza := incoming_stanza.(type) { case *xmpp.Message: + if stanza.GetHeader() == nil { continue } botdata.handleIncomingMessageDialog(*stanza, xmppout, jabber_events) + if stanza.Type == "error" || stanza.Error != nil { + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if handleStanzaError() { return } + continue + } else { error_count = 0 } case *xmpp.Presence: if stanza.GetHeader() == nil { continue } if stanza.Type == "error" || stanza.Error != nil { - Syslog_.Printf("XMPP Presence Error: %s", stanza.Error.Error()) - } + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if handleStanzaError() { return } + continue + } else { error_count = 0 } switch stanza.GetHeader().Type { case "subscribe": xmppout <- botdata.makeXMPPPresence(stanza.GetHeader().From, "subscribed", "", "") @@ -340,11 +357,15 @@ func (botdata *XmppBot) handleIncomingXMPPStanzas(xmppin <- chan xmpp.Stanza, xm default: jabber_events <- JabberEvent{stanza.GetHeader().From, true, R3NoChange, false} } + case *xmpp.Iq: if stanza.GetHeader() == nil { continue } if stanza.Type == "error" || stanza.Error != nil { - Syslog_.Printf("XMPP Iq Error: %s", stanza.Error.Error()) - } + Syslog_.Printf("XMPP %T Error: %s", stanza, stanza) + if handleStanzaError() { return } + continue + } else { error_count = 0 } + if HandleServerToClientPing(stanza, xmppout) {continue} //if true then routine handled it and we can continue Debug_.Printf("Unhandled Iq: %s", stanza) } -- 1.7.10.4