diff options
author | Wim <wim@42.be> | 2017-05-08 20:44:36 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-05-08 20:44:36 +0200 |
commit | 2e703472f175ec930a939b47cf87c11f6cb0d613 (patch) | |
tree | c7653d97be91da96682d482c624a3e8621bd36f9 | |
parent | 8fede90b9e52f486b863ed61948ed625cdd15948 (diff) | |
download | matterbridge-msglm-2e703472f175ec930a939b47cf87c11f6cb0d613.tar.gz matterbridge-msglm-2e703472f175ec930a939b47cf87c11f6cb0d613.tar.bz2 matterbridge-msglm-2e703472f175ec930a939b47cf87c11f6cb0d613.zip |
Fix crash on reconnects when server is down. Closes #163
-rw-r--r-- | matterclient/matterclient.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index d234fb34..e579537b 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -108,13 +108,24 @@ func (m *MMClient) Login() error { m.Client = model.NewClient(uriScheme + m.Credentials.Server) m.Client.HttpClient.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}} m.Client.HttpClient.Timeout = time.Second * 10 - // bogus call to get the serverversion - m.Client.GetClientProperties() - if firstConnection && !supportedVersion(m.Client.ServerVersion) { - return fmt.Errorf("unsupported mattermost version: %s", m.Client.ServerVersion) + + for { + d := b.Duration() + // bogus call to get the serverversion + m.Client.GetClientProperties() + if firstConnection && !supportedVersion(m.Client.ServerVersion) { + return fmt.Errorf("unsupported mattermost version: %s", m.Client.ServerVersion) + } + m.ServerVersion = m.Client.ServerVersion + if m.ServerVersion == "" { + m.log.Debugf("Server not up yet, reconnecting in %s", d) + time.Sleep(d) + } else { + m.log.Infof("Found version %s", m.ServerVersion) + break + } } - m.ServerVersion = m.Client.ServerVersion - m.log.Infof("Found version %s", m.ServerVersion) + b.Reset() var myinfo *model.Result var appErr *model.AppError |