Fix sigsev when conLdap.Close() after connection was droped remotely
This commit is contained in:
parent
6e9947809c
commit
8ac556ad8b
@ -26,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "1.0.0-rc4"
|
version = "1.0.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -284,7 +284,11 @@ func searchLdap(searchReq *ldap.SearchRequest, attempt int) (*ldap.SearchResult,
|
|||||||
if err != nil && strings.HasSuffix(err.Error(), "ldap: connection closed") {
|
if err != nil && strings.HasSuffix(err.Error(), "ldap: connection closed") {
|
||||||
logstream.Error("LDAP connection closed, retrying")
|
logstream.Error("LDAP connection closed, retrying")
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
conLdap.Close()
|
// 16/01/2023: panic: runtime error: invalid memory address or nil pointer dereference
|
||||||
|
// probably bc connection is already closed
|
||||||
|
if conLdap != nil {
|
||||||
|
conLdap.Close()
|
||||||
|
}
|
||||||
conLdap, err = connectLdap()
|
conLdap, err = connectLdap()
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -302,12 +306,12 @@ func connectLdap() (*ldap.Conn, error) {
|
|||||||
conLdap, err = ldap.DialURL(*ldapURL)
|
conLdap, err = ldap.DialURL(*ldapURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logstream.Errorf("Error dialing LDAP on %s: %v\n", *ldapURL, err)
|
logstream.Errorf("Error dialing LDAP on %s: %v\n", *ldapURL, err)
|
||||||
return conLdap, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = conLdap.Bind(*ldapUser, *ldapPass)
|
err = conLdap.Bind(*ldapUser, *ldapPass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logstream.Errorf("Error binding LDAP: %s", err)
|
logstream.Errorf("Error binding LDAP: %s", err)
|
||||||
return conLdap, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return conLdap, err
|
return conLdap, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user