diff --git a/mxrouter.go b/mxrouter.go index 0146511..8addb16 100644 --- a/mxrouter.go +++ b/mxrouter.go @@ -33,7 +33,7 @@ import ( ) const ( - version = "0.9.8" + version = "0.9.9" // Match le nom de domaine, soit les 2 dernieres chaines separees par un point. // Peut aussi terminer par un point (Ex: srv.domaine.com. => domaine.com) DomainRegexpFormat = `([0-9A-Za-z\-]*)\.([0-9A-Za-z\-]*)(?:\.)?$` @@ -55,22 +55,38 @@ var ( timeout *int ) +// attempt is useless now. It was introduced to break after N attempts, but this is not implemented. Should it be? func ldapSearch(searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult, error) { mutex.Lock() result, err := conLdap.Search(searchReq) mutex.Unlock() // Let's just manage connection errors here - if err != nil && strings.HasSuffix(err.Error(), "ldap: connection closed") { - logstream.Err("LDAP connection closed, retrying") - mutex.Lock() - conLdap.Close() - conLdap, err = connectLdap() - mutex.Unlock() - if err != nil { - return result, err - } else { - attempt = attempt + 1 - return ldapSearch(searchReq, attempt) + if err != nil { + if strings.HasSuffix(err.Error(), "ldap: connection closed") { + logstream.Err("LDAP connection closed, retrying") + mutex.Lock() + conLdap.Close() + conLdap, err = connectLdap() + mutex.Unlock() + if err != nil { + return result, err + } else { + attempt = attempt + 1 + return ldapSearch(searchReq, attempt) + } + } else if err == ldap.ErrNilConnection { + logstream.Err("LDAP connection is nil, reconnecting") + mutex.Lock() + // conLdap is nil so this would be a sigsegv/panic + //conLdap.Close() + conLdap, err = connectLdap() + mutex.Unlock() + if err != nil { + return result, err + } else { + attempt = attempt + 1 + return ldapSearch(searchReq, attempt) + } } }