Repository: kubernetes/kubernetes (language: go)

Issue:
Wrong error is passed and printed upon websocket message read failure
### What happened?

When `kubectl cp` using websockets fails on reading the message, a nil error is printed instead actual failure reason due to wrong variable used in the websocket implementation.

```
kubectl -n=gather-artifacts cp --retries=42 -c=wait-for-artifacts must-gather:/tmp/artifacts /logs/artifacts/must-gather/0
tar: Removing leading `/' from member names
E0307 11:05:27.652791    1349 v2.go:167] "Unhandled Error" err="read message: %!w(<nil>)"
E0307 11:05:27.652794    1349 v2.go:150] "Unhandled Error" err="read message: %!w(<nil>)"
error: error reading from error stream: read message: %!w(<nil>) 
```

### What did you expect to happen?

Get real failure reason instead of nil error.

### How can we reproduce it (as minimally and precisely as possible)?

It happens from time to time when using `kubectl cp` to copy directory having huge number of files.

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version -o yaml
clientVersion:
  buildDate: "2025-03-02T01:21:59Z"
  compiler: gc
  gitCommit: 948afe5ca072329a73c8e79ed5938717a5cb3d21
  gitTreeState: clean
  gitVersion: v1.31.1
  goVersion: go1.22.6
  major: "1"
  minor: "31"
  platform: linux/amd64
kustomizeVersion: v5.4.2
serverVersion:
  buildDate: "2025-02-17T04:15:03Z"
  compiler: gc
  gitCommit: 84f41c2100b3d5f238e0dc12381df8fa8ad306bf
  gitTreeState: clean
  gitVersion: v1.31.6-gke.1064000
  goVersion: go1.22.12 X:boringcrypto
  major: "1"
  minor: "31"
  platform: linux/amd64

```

</details>


### Cloud provider

<details>
GKE
</details>



Discussion / hints:
This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.

The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.


<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
</details>
/sig api-machinery

Fix patch:
diff --git a/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go b/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go
index 7e7703ca6b1c4..cea26a0b5575c 100644
--- a/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go
+++ b/staging/src/k8s.io/client-go/tools/remotecommand/websocket.go
@@ -312,7 +312,7 @@ func (c *wsStreamCreator) readDemuxLoop(bufferSize int, period time.Duration, de
 				if errRead == io.EOF {
 					break
 				}
-				c.closeAllStreamReaders(fmt.Errorf("read message: %w", err))
+				c.closeAllStreamReaders(fmt.Errorf("read message: %w", errRead))
 				return
 			}
 		}


Test patch: