From 6d1e6db47e637e076df0ddb0a3be95b3c32d4c6b Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 15 Oct 2023 16:36:48 +0200 Subject: [PATCH] Check if listener is not nil before closing it --- network/engine.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/network/engine.go b/network/engine.go index a1820b79..fba52f92 100644 --- a/network/engine.go +++ b/network/engine.go @@ -52,10 +52,12 @@ func (engine *Engine) Stop(ctx context.Context) error { defer cancel() engine.running.Store(false) - if err := engine.listener.Close(); err != nil { - engine.stopServer <- struct{}{} - close(engine.stopServer) - return gerr.ErrCloseListenerFailed.Wrap(err) + if engine.listener != nil { + if err := engine.listener.Close(); err != nil { + engine.stopServer <- struct{}{} + close(engine.stopServer) + return gerr.ErrCloseListenerFailed.Wrap(err) + } } engine.stopServer <- struct{}{} close(engine.stopServer)