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

runtime/map Non-atomic hashWriting flag may cause data corruption #31516

Closed
samaingw opened this issue Apr 17, 2019 · 1 comment
Closed

runtime/map Non-atomic hashWriting flag may cause data corruption #31516

samaingw opened this issue Apr 17, 2019 · 1 comment

Comments

@samaingw
Copy link

What version of Go are you using (go version)?

master

Does this issue reproduce with the latest release?

Yes.

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

Any.

What did you do?

Inspect runtime map for concurrent access checks. I am not talking about sync.map.

What did you expect to see?

hashWriting flag (un)set with atomic operations.

What did you see instead?

Non atomic operations like in those lines:
mapaccess flag set,
mapaccess flag reset.

These instructions compile to the following assembly instructions, without any prior lock:

  1. mov from memory into register;
  2. <binary_operation> (e.g. xor, and, ...);
  3. mov from register back into memory.

These instructions, as well as the checks above them, are not guaranteed to be atomic.
As a consequence, we may have (rare but some) cases were a concurrent access is not detected.

@randall77
Copy link
Contributor

This is ok as is, I think. The checks that this flag enables are best effort. They are intended to help catch races in user programs, but there are no guarantees.

Accesses which would cause problems, like simultaneous writes to a map, are already forbidden by the language spec.

@golang golang locked and limited conversation to collaborators Apr 17, 2020
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