commit | 88e2d1c7f9a20e3476dd2cca5112e374c8911eed | [log] [tgz] |
---|---|---|
author | Peter Weinberger <pjw@google.com> | Sat Dec 23 07:59:06 2023 -0500 |
committer | Peter Weinberger <pjw@google.com> | Tue Jan 16 21:27:45 2024 +0000 |
tree | 44d5585cfff081925d261432efc4e9e82717719a | |
parent | 76c6b0d9169aaf3a6498afb4ce977524786e15e6 [diff] |
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 <rfindley@google.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Peter Weinberger <pjw@google.com>
This repository holds the Go Telemetry server code and libraries.
This repository uses eslint to format TS files, stylelint to format CSS files, and prettier to format TS, CSS, Markdown, and YAML files.
See the style guides:
It is encouraged that all TS and CSS code be run through formatters before submitting a change. However, it is not a strict requirement enforced by CI.
./npm install
./npm run all
This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.
The main issue tracker for the time repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/telemetry:” in the subject line, so it is easy to find.