From 1c081ab7bc5ed1809b42db6c7db255891e288ed4 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 6 Dec 2024 14:40:22 -0500 Subject: [PATCH] fix(daemon): close listener only once --- pkg/daemon/daemon.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index de65cba75..9eaa7661e 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -305,12 +305,20 @@ func (d *GitDaemon) handleClient(conn net.Conn) { // Close closes the underlying listener. func (d *GitDaemon) Close() error { - d.once.Do(func() { close(d.finished) }) - err := d.listener.Close() + err := d.closeListener() d.conns.CloseAll() // nolint: errcheck return err } +// closeListener closes the listener and the finished channel. +func (d *GitDaemon) closeListener() (err error) { + d.once.Do(func() { + close(d.finished) + err = d.listener.Close() + }) + return +} + // Shutdown gracefully shuts down the daemon. func (d *GitDaemon) Shutdown(ctx context.Context) error { // in the case when git daemon was never started @@ -318,8 +326,7 @@ func (d *GitDaemon) Shutdown(ctx context.Context) error { return nil } - d.once.Do(func() { close(d.finished) }) - err := d.listener.Close() + err := d.closeListener() finished := make(chan struct{}, 1) go func() { d.wg.Wait()