code: func (n *Node) Stop(ctx context.Context) error {
  	select {
  	case <-n.started:
  	default:
  		return errNodeNotStarted
  	}
  	// ask agent to clean up assignments
  	n.Lock()
  	if n.agent != nil {
  		if err := n.agent.Leave(ctx); err != nil {
  			log.G(ctx).WithError(err).Error("agent failed to clean up assignments")
  		}
  	}
  	n.Unlock()
  
  	n.stopOnce.Do(func() {
  		close(n.stopped)
  	})
  
  	select {
  	case <-n.closed:
  		return nil
  	case <-ctx.Done():
  		return ctx.Err()
  	}
  }
docs: // Stop stops node execution