internal: fix crash when port 9000 is in use (#4863)
fix crash when port 9000 is in use Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
885aeddbdc
commit
41d17dc543
|
@ -17,7 +17,7 @@ import (
|
||||||
func GenerateSelfSignedCert() (tls.Certificate, error) {
|
func GenerateSelfSignedCert() (tls.Certificate, error) {
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate private key: %v", err)
|
log.WithError(err).Warning("Failed to generate private key")
|
||||||
return tls.Certificate{}, err
|
return tls.Certificate{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func GenerateSelfSignedCert() (tls.Certificate, error) {
|
||||||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
||||||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate serial number: %v", err)
|
log.WithError(err).Warning("Failed to generate serial number")
|
||||||
return tls.Certificate{}, err
|
return tls.Certificate{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ func (ls *LDAPServer) StartLDAPServer() error {
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", listen)
|
ln, err := net.Listen("tcp", listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ls.log.WithField("listen", listen).WithError(err).Fatalf("listen failed")
|
ls.log.WithField("listen", listen).WithError(err).Warning("Failed to listen (SSL)")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
proxyListener := &proxyproto.Listener{Listener: ln}
|
proxyListener := &proxyproto.Listener{Listener: ln}
|
||||||
defer proxyListener.Close()
|
defer proxyListener.Close()
|
||||||
|
|
|
@ -46,7 +46,8 @@ func (ls *LDAPServer) StartLDAPTLSServer() error {
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", listen)
|
ln, err := net.Listen("tcp", listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ls.log.WithField("listen", listen).WithError(err).Fatalf("listen failed")
|
ls.log.WithField("listen", listen).WithError(err).Warning("Failed to listen")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyListener := &proxyproto.Listener{Listener: ln}
|
proxyListener := &proxyproto.Listener{Listener: ln}
|
||||||
|
|
|
@ -115,7 +115,8 @@ func (ps *ProxyServer) ServeHTTP() {
|
||||||
listenAddress := config.Get().Listen.HTTP
|
listenAddress := config.Get().Listen.HTTP
|
||||||
listener, err := net.Listen("tcp", listenAddress)
|
listener, err := net.Listen("tcp", listenAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ps.log.WithField("listen", listenAddress).WithError(err).Fatalf("listen failed")
|
ps.log.WithField("listen", listenAddress).WithError(err).Warning("Failed to listen")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
proxyListener := &proxyproto.Listener{Listener: listener}
|
proxyListener := &proxyproto.Listener{Listener: listener}
|
||||||
defer proxyListener.Close()
|
defer proxyListener.Close()
|
||||||
|
@ -137,6 +138,7 @@ func (ps *ProxyServer) ServeHTTPS() {
|
||||||
ln, err := net.Listen("tcp", listenAddress)
|
ln, err := net.Listen("tcp", listenAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ps.log.WithError(err).Warning("Failed to listen (TLS)")
|
ps.log.WithError(err).Warning("Failed to listen (TLS)")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
proxyListener := &proxyproto.Listener{Listener: web.TCPKeepAliveListener{TCPListener: ln.(*net.TCPListener)}}
|
proxyListener := &proxyproto.Listener{Listener: web.TCPKeepAliveListener{TCPListener: ln.(*net.TCPListener)}}
|
||||||
defer proxyListener.Close()
|
defer proxyListener.Close()
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (ws *WebServer) listenTLS() {
|
||||||
|
|
||||||
ln, err := net.Listen("tcp", config.Get().Listen.HTTPS)
|
ln, err := net.Listen("tcp", config.Get().Listen.HTTPS)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ws.log.WithError(err).Fatalf("failed to listen (TLS)")
|
ws.log.WithError(err).Warning("failed to listen (TLS)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
proxyListener := &proxyproto.Listener{Listener: web.TCPKeepAliveListener{TCPListener: ln.(*net.TCPListener)}}
|
proxyListener := &proxyproto.Listener{Listener: web.TCPKeepAliveListener{TCPListener: ln.(*net.TCPListener)}}
|
||||||
|
|
|
@ -63,7 +63,8 @@ func (ws *WebServer) Shutdown() {
|
||||||
func (ws *WebServer) listenPlain() {
|
func (ws *WebServer) listenPlain() {
|
||||||
ln, err := net.Listen("tcp", config.Get().Listen.HTTP)
|
ln, err := net.Listen("tcp", config.Get().Listen.HTTP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ws.log.WithError(err).Fatal("failed to listen")
|
ws.log.WithError(err).Warning("failed to listen")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
proxyListener := &proxyproto.Listener{Listener: ln}
|
proxyListener := &proxyproto.Listener{Listener: ln}
|
||||||
defer proxyListener.Close()
|
defer proxyListener.Close()
|
||||||
|
|
Reference in New Issue