server: Use separate context to cancel listeners

Use a separate context to cancel listeners so that cancelling the
listener does not cancel it's connections.
This commit is contained in:
Adnan Maolood 2021-02-21 00:41:39 -05:00
parent 6c701ad9fe
commit 3fa55b52dd

View File

@ -205,7 +205,7 @@ func (srv *Server) Serve(ctx context.Context, l net.Listener) error {
return ErrServerClosed
}
ctx, cancel := context.WithCancel(ctx)
lnctx, cancel := context.WithCancel(ctx)
defer cancel()
srv.trackListener(&l, cancel)
@ -218,8 +218,8 @@ func (srv *Server) Serve(ctx context.Context, l net.Listener) error {
}()
select {
case <-ctx.Done():
return ctx.Err()
case <-lnctx.Done():
return lnctx.Err()
case err := <-errch:
return err
}