-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/counter: fix file rotation panics
Weekly, the memory-mapped counter file is replaced by a new one. If this fails, using counters may panic. This CL fixes the code to avoid the above panics by setting the counter's file's mapping to nil while there is a danger that an existing mapping is no longer valid. The reader can understand the changes using the new TestRotateCounters at line 99 to see what happens when remapping fails. 1. In the existing code, the current.Lookup at existing line 308 will fault 2. Commenting out that code delays the fault to the c.Inc() at line 106 of rotate_test.go. 3. So the counters have dangling pointers. These have to be reset. This is done by f.current.Store(nil), and running a cleanup function at line 313 in the new code. The cleanup function resets all the counter pointers, and then cleans up the old mapping, if there is one. (The code to reset the counters cannot be run while f.mu is locked.) 4. But there is the same problem with counter pointers pointing to the old mapping even after the file points to the new mapping. The same solution works, resetting the counter pointer, and then closing the old mapping. (The old code freed the mapping too soon.) In both cases (3 and 4), if a counter pointer is used, it will point to a valid mapping (nil is fine; the increment goes into the counter's state) Summary: an old mapping cannot be removed until all the file's counters point to a new mapping. The CL also Fixes some internal documentation, Fixes a time-related test error that only showed up in Eastern time evening, Adds a test showing the life of a counter and testing mapping failure in file rotation. Fixes: golang/go#64577 Change-Id: I3e4775fb527e94d8a32505c8d77a131659b0a82a Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/552276 Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Peter Weinberger <[email protected]>
- Loading branch information
Showing
3 changed files
with
255 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.