A panic was encountered where writes to progress status hit a nil
writer. While not easy to reproduce, this commit fixes a likely culprit.
The use of atomics in the controller was not safe against a race such as
the following:
1. One goroutine calls Start, incrementing count but not yet setting
writer.
2. A second goroutine calls Start, increments count again but sees that
count >1 and thus doesn't try to set writer.
3. The second goroutine then calls Status, assuming the writer has been
set, but the first goroutine still hasn't set the writer yet, causing
a nil pointer exception.
This commit fixes that issue by just using a mutex instead of atomics.
It also adds a nil check for the writer just to be safe against panics
due to unknown issues in the future as missing a status update is much
better than buildkitd crashing.
Signed-off-by: Erik Sipsma <erik@sipsma.dev>