Skip to content

Commit

Permalink
fix: git daemon listens only when starting it (#607)
Browse files Browse the repository at this point in the history
This was inconsistent with the other servers.

Co-authored-by: Jonatan Wallmander <jonatan.wallmander@kdab.com>
  • Loading branch information
jaw and Jonatan Wallmander authored Dec 4, 2024
1 parent 5d5c55e commit 3aa71e0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ func NewGitDaemon(ctx context.Context) (*GitDaemon, error) {
conns: connections{m: make(map[net.Conn]struct{})},
logger: log.FromContext(ctx).WithPrefix("gitdaemon"),
}
listener, err := net.Listen("tcp", d.addr)
if err != nil {
return nil, err
}
d.listener = listener
return d, nil
}

// Start starts the Git TCP daemon.
func (d *GitDaemon) Start() error {
// listen on the socket
{
listener, err := net.Listen("tcp", d.addr)
if err != nil {
return err

Check failure on line 79 in pkg/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / lint-soft

error returned from external package is unwrapped: sig: func net.Listen(network string, address string) (net.Listener, error) (wrapcheck)
}
d.listener = listener
}

// close eventual connections to the socket
defer d.listener.Close() // nolint: errcheck

d.wg.Add(1)
Expand Down Expand Up @@ -308,6 +313,11 @@ func (d *GitDaemon) Close() error {

// 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()
finished := make(chan struct{}, 1)
Expand Down

0 comments on commit 3aa71e0

Please sign in to comment.