kubernetes-sigs / kubetest2

Kubetest2 is the framework for launching and running end-to-end tests on Kubernetes.
Apache License 2.0
326 stars 105 forks source link

Unsafe concurrent use of bytes.Buffer #210

Closed liggitt closed 1 year ago

liggitt commented 1 year ago

https://github.com/kubernetes-sigs/kubetest2/blob/master/pkg/process/junitexec.go#L59-L61 uses the same bytes.Buffer in two output streams, which means it can be written to concurrently. That is not threadsafe.

This panics randomly with changes made to bytes.Buffer growing in go1.19.

The code should be changes to make use of the buffer threadsafe or use two separate buffers

BenTheElder commented 1 year ago

For the next time we run into something like this: It's actually slightly more complex than that in the general case but not here since we always set os.Stdout and os.Stderr

This should use a mutex wrapped buffer.

BenTheElder commented 1 year ago

Actually, I will just do this before PRing myself to emeritus, since this is such a trivial but important fix ...