code: func setupContextDeadliner(ctx context.Context, conn net.Conn) (done func(*error)) {
  	var (
  		quit      = make(chan struct{})
  		interrupt = make(chan error, 1)
  	)
  	go func() {
  		select {
  		case <-quit:
  			interrupt <- nil
  		case <-ctx.Done():
  			// Cancel i/o immediately.
  			conn.SetDeadline(aLongTimeAgo)
  			interrupt <- ctx.Err()
  		}
  	}()
  	return func(err *error) {
  		close(quit)
  		// If ctx.Err() is non-nil and the original err is net.Error with
  		// Timeout() == true, then it means that I/O was canceled by us by
  		// SetDeadline(aLongTimeAgo) call, or by somebody else previously
  		// by conn.SetDeadline(x).
  		//
  		// Even on race condition when both deadlines are expired
  		// (SetDeadline() made not by us and context's), we prefer ctx.Err() to
  		// be returned.
  		if ctxErr := <-interrupt; ctxErr != nil && (*err == nil || isTimeoutError(*err)) {
  			*err = ctxErr
  		}
  	}
  }
docs: // setupContextDeadliner is a helper function that starts connection I/O
  // interrupter goroutine.
  //
  // Started goroutine calls SetDeadline() with long time ago value when context
  // become expired to make any I/O operations failed. It returns done function
  // that stops started goroutine and maps error received from conn I/O methods
  // to possible context expiration error.
  //
  // In concern with possible SetDeadline() call inside interrupter goroutine,
  // caller passes pointer to its I/O error (even if it is nil) to done(&err).
  // That is, even if I/O error is nil, context could be already expired and
  // connection "poisoned" by SetDeadline() call. In that case done(&err) will
  // store at *err ctx.Err() result. If err is caused not by timeout, it will
  // leaved untouched.