Skip to content

Commit

Permalink
fix(daemon): close listener only once
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 6, 2024
1 parent b450d10 commit 1c081ab
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,28 @@ 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
if d.listener == nil {
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()
Expand Down

0 comments on commit 1c081ab

Please sign in to comment.