]> Cypherpunks repositories - gostls13.git/commit
os: fix race condition in readdir by atomically initializing dirinfo
authorAmirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
Mon, 3 Feb 2025 05:56:31 +0000 (05:56 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 5 Feb 2025 02:18:11 +0000 (18:18 -0800)
commitbe2b809e5b888ed0ee636f1e07340640ffd88842
tree45799b67615459374b7e206dc78cc249eae449a9
parenta1ea78c470d3136b7aed42a4d8b94497563f98ea
os: fix race condition in readdir by atomically initializing dirinfo

This change ensures that dirinfo in the File struct is initialized atomically,
avoiding redundant allocations when multiple goroutines access it concurrently.
Instead of creating separate buffers, we now use CompareAndSwap to guarantee
thread-safe initialization and reduce unnecessary memory usage.

Although this is not a strict race condition, the update enhances efficiency by
eliminating duplicate allocations and ensuring safer concurrent access.

Fixes #71496.

Change-Id: If08699a94afa05611cdf67e82a5957a8d8f9d5c8
GitHub-Last-Rev: 1e1f6191439cf3ad32f3ba54bba5a0185dd55b14
GitHub-Pull-Request: golang/go#71501
Reviewed-on: https://go-review.googlesource.com/c/go/+/645720
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/dir_plan9.go
src/os/dir_unix.go