Open bcmills opened 2 years ago
Unless we're willing to put locks everywhere, I'm not sure what we can say beyond saying to read the documents for the operating system.
Change https://go.dev/cl/438347 mentions this issue: os: add test that concurrent calls to Close on a pipe are OK
As it happens, we actually already have all the required locks for regular files or pipes, on all systems other than Plan 9. I've already sent CL 438347 to fix Plan 9.
We have the locks because we need them anyhow for the runtime poller.
The current exception is for directories. For directories os files have a dirInfo
field. There are no locks around access to that field.
Change https://go.dev/cl/439195 mentions this issue: os/exec: remove protection against a duplicate Close on StdinPipe
Change https://go.dev/cl/439595 mentions this issue: os: ensure that concurrent I/O and Close on a pipe are OK
What version of Go are you using (
go version
)?https://pkg.go.dev/os@go1.19.1
Does this issue reproduce with the latest release?
Yes.
What did you do?
For #50436, I'm attempting to unblock reads on a
*File
returned byos.Pipe
while it is being read concurrently by a user-controlled goroutine. The user-controlled goroutine may legitimately call theClose
method, and may expect to be able to access other methods (such asSetDeadline
) via type-assertion.What did you expect to see?
Given #6270, #7970, #9307, #17647 and https://go.dev/cl/65490, I expected the documentation for `*os.File to describe which methods are safe to invoke concurrently and under what conditions.
What did you see instead?
The only mention of concurrency I could find in https://pkg.go.dev/os@go1.19.1 says this:
That seems to imply that at least some of the
File
methods may be invoked concurrently, but isn't explicit about which ones.I see unsynchronized writes in the
Close
implementation on bothunix
andplan9
(but maybe notwindows
?); it's not obvious to me which other methods are or aren't safe.(CC @rsc @ianlancetaylor @robpike from previous
*File
race conditions.)