code: func (s *Server) serve(cb ServeFunc) error {
  	s.l.Lock()
  	if s.listener == nil {
  		s.l.Unlock()
  		return errors.New("already closed")
  	}
  	listener := s.listener // accessed outside the lock
  	ctx := s.ctx
  	s.l.Unlock()
  
  	err := cb(ctx, listener, &s.wg) // blocks until killServe() is called
  	s.wg.Wait()                     // waits for all pending requests
  
  	// If it was a planned shutdown with killServe(), ignore the error. It says
  	// that the listening socket was closed.
  	s.l.Lock()
  	if s.listener == nil {
  		err = nil
  	}
  	s.l.Unlock()
  
  	if err != nil {
  		return errors.Annotate(err, "error in the serving loop").Err()
  	}
  	return nil
  }
docs: // serve runs the serving loop.
  //
  // It unblocks once killServe is called and all pending requests are served.
  //
  // Returns nil if serving was stopped by killServe or non-nil if it failed for
  // some other reason.