mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-21 19:50:14 +00:00
fix: handle panics in tailscale service
This commit is contained in:
@@ -98,7 +98,7 @@ func (app *BootstrapApp) calculateListenerPolicy() []Listener {
|
|||||||
l := []Listener{}
|
l := []Listener{}
|
||||||
|
|
||||||
if !app.config.Server.ConcurrentListenersEnabled {
|
if !app.config.Server.ConcurrentListenersEnabled {
|
||||||
if app.config.Tailscale.Enabled {
|
if app.services.tailscaleService != nil {
|
||||||
l = append(l, ListenerTailscale)
|
l = append(l, ListenerTailscale)
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func (app *BootstrapApp) calculateListenerPolicy() []Listener {
|
|||||||
l = append(l, ListenerUnix)
|
l = append(l, ListenerUnix)
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.config.Tailscale.Enabled {
|
if app.services.tailscaleService != nil {
|
||||||
l = append(l, ListenerTailscale)
|
l = append(l, ListenerTailscale)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,12 @@ func (app *BootstrapApp) serve(listener net.Listener, server *http.Server, name
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), model.GracefulShutdownTimeout*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), model.GracefulShutdownTimeout*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
err := server.Shutdown(ctx)
|
err := server.Shutdown(ctx)
|
||||||
if err != nil {
|
if err != nil &&
|
||||||
|
// With tailscale, the goroutine for shutting down the tailscale connection
|
||||||
|
// runs first and causes the connection the tailscale listener is running on to close
|
||||||
|
// first so, the shutdown fails
|
||||||
|
// TODO: add priority to the goroutine shutdowns
|
||||||
|
!errors.Is(err, net.ErrClosed) {
|
||||||
app.log.App.Error().Err(err).Msgf("Failed to shutdown %s listener gracefully", name)
|
app.log.App.Error().Err(err).Msgf("Failed to shutdown %s listener gracefully", name)
|
||||||
}
|
}
|
||||||
listener.Close()
|
listener.Close()
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ import (
|
|||||||
"tailscale.com/tsnet"
|
"tailscale.com/tsnet"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
TsnetErrClosed = errors.New("tsnet: use of closed network connection")
|
||||||
|
)
|
||||||
|
|
||||||
type TailscaleWhoisResponse struct {
|
type TailscaleWhoisResponse struct {
|
||||||
UserID string
|
UserID string
|
||||||
LoginName string
|
LoginName string
|
||||||
@@ -99,10 +103,10 @@ func (ts *TailscaleService) watchAndClose() {
|
|||||||
ts.srv = nil
|
ts.srv = nil
|
||||||
ts.mu.Unlock()
|
ts.mu.Unlock()
|
||||||
if ln != nil {
|
if ln != nil {
|
||||||
(*ts.ln).Close()
|
(*ln).Close()
|
||||||
}
|
}
|
||||||
if srv != nil {
|
if srv != nil {
|
||||||
ts.srv.Close()
|
srv.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user