From aafb7bf120d30c37219686a5bb528794b0ab44a2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 7 Jun 2022 10:46:21 +0100 Subject: [PATCH] Avoid panicking unnecessarily when shutting down the `gobind` P2P demos (#2520) --- build/gobind-pinecone/monolith.go | 18 +++++++++++++++--- build/gobind-yggdrasil/monolith.go | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/build/gobind-pinecone/monolith.go b/build/gobind-pinecone/monolith.go index 664ca85d..b44e110a 100644 --- a/build/gobind-pinecone/monolith.go +++ b/build/gobind-pinecone/monolith.go @@ -261,7 +261,7 @@ func (m *DendriteMonolith) Start() { cfg.MSCs.MSCs = []string{"msc2836", "msc2946"} cfg.ClientAPI.RegistrationDisabled = false cfg.ClientAPI.OpenRegistrationWithoutVerificationEnabled = true - if err := cfg.Derive(); err != nil { + if err = cfg.Derive(); err != nil { panic(err) } @@ -342,11 +342,23 @@ func (m *DendriteMonolith) Start() { go func() { m.logger.Info("Listening on ", cfg.Global.ServerName) - m.logger.Fatal(m.httpServer.Serve(m.PineconeQUIC.Protocol("matrix"))) + + switch m.httpServer.Serve(m.PineconeQUIC.Protocol("matrix")) { + case net.ErrClosed, http.ErrServerClosed: + m.logger.Info("Stopped listening on ", cfg.Global.ServerName) + default: + m.logger.Fatal(err) + } }() go func() { logrus.Info("Listening on ", m.listener.Addr()) - logrus.Fatal(http.Serve(m.listener, httpRouter)) + + switch http.Serve(m.listener, httpRouter) { + case net.ErrClosed, http.ErrServerClosed: + m.logger.Info("Stopped listening on ", cfg.Global.ServerName) + default: + m.logger.Fatal(err) + } }() } diff --git a/build/gobind-yggdrasil/monolith.go b/build/gobind-yggdrasil/monolith.go index 991bc462..99b180c8 100644 --- a/build/gobind-yggdrasil/monolith.go +++ b/build/gobind-yggdrasil/monolith.go @@ -170,11 +170,11 @@ func (m *DendriteMonolith) Start() { go func() { m.logger.Info("Listening on ", ygg.DerivedServerName()) - m.logger.Fatal(m.httpServer.Serve(ygg)) + m.logger.Error(m.httpServer.Serve(ygg)) }() go func() { logrus.Info("Listening on ", m.listener.Addr()) - logrus.Fatal(http.Serve(m.listener, httpRouter)) + logrus.Error(http.Serve(m.listener, httpRouter)) }() go func() { logrus.Info("Sending wake-up message to known nodes")