Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rlock - unexpected behavior #24035

Closed
recoilme opened this issue Feb 22, 2018 · 4 comments
Closed

Rlock - unexpected behavior #24035

recoilme opened this issue Feb 22, 2018 · 4 comments

Comments

@recoilme
Copy link

recoilme commented Feb 22, 2018

go version go1.8.1 darwin/amd64

Does this issue reproduce with the latest release?

  • yes

What operating system and processor architecture are you using (go env)?

mac os 10.12.6

What did you do?

write and read in file from multiple goroutine at same time

What did you expect to see?

I write with lock and read with rlock same file. And read with seek (0,0)

What did you see instead?

When i use Rlock + Seek to the beginning of file - seek return 0 but really not seek at beginning of file
With Lock - not reproduce

reproduce: https://github.com/recoilme/slowpoke/blob/master/syncfile/syncfile_test.go#L46

problem here: https://github.com/recoilme/slowpoke/blob/master/syncfile/syncfile.go#L50

@recoilme
Copy link
Author

i test on mac os with latest release: go version go1.10 darwin/amd64 - same problem
i test on debian with go version go1.9.2 linux/amd64 - same problem

@recoilme
Copy link
Author

Link on commit recoilme/slowpoke@4912806

@recoilme
Copy link
Author

With Rlock - when writing in file seek positioning at wrong position
For example - i have 123456 in file
when i read first 3 bytes from this file i expect to see 123
but i see 123 or 456.

I open file with os.O_CREATE|os.O_RDWR
i write to file with Lock mutex
i read from file with RLock mutex
With Lock mutex - all work as expected

@bradfitz
Copy link
Contributor

You can't seek around a file concurrently. This isn't a Go question or problem. The seek position is stored in the kernel, associated with the open file. You'll need to use ReadAt or use separate files.

For questions about Go, see https://golang.org/wiki/Questions.

@golang golang locked and limited conversation to collaborators Feb 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants