From 7633cca3b166f88d0f15f763e774476df6b1c56a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 21 Aug 2024 15:54:36 +0200 Subject: [PATCH] Fix exit signal handling --- relay/cmd/main.go | 10 ++++++---- relay/server/listener/ws/listener.go | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/relay/cmd/main.go b/relay/cmd/main.go index 22dc025a8..dc39beaa5 100644 --- a/relay/cmd/main.go +++ b/relay/cmd/main.go @@ -166,11 +166,13 @@ func execute(cmd *cobra.Command, args []string) error { return fmt.Errorf("failed to create relay server: %v", err) } log.Infof("server will be available on: %s", srv.InstanceURL()) - err = srv.Listen(srvListenerCfg) - if err != nil { - return fmt.Errorf("failed to bind server: %s", err) - } + go func() { + if err := srv.Listen(srvListenerCfg); err != nil { + log.Errorf("failed to bind server: %s", err) + } + }() + // it will block until exit signal waitForExitSignal() err = srv.Close() diff --git a/relay/server/listener/ws/listener.go b/relay/server/listener/ws/listener.go index 51a578dc4..673a5e19a 100644 --- a/relay/server/listener/ws/listener.go +++ b/relay/server/listener/ws/listener.go @@ -38,7 +38,6 @@ func (l *Listener) Listen(acceptFn func(conn net.Conn)) error { var err error if l.TLSConfig != nil { err = l.server.ListenAndServeTLS("", "") - } else { err = l.server.ListenAndServe() }