-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/log: fix a bug in closeFileLocked() and strengthen the API
Prior to this patch, `closeFileLocked()` would inconditionally reset the redirection of internal stderr writes back to the original stderr stream (`OrigStderr`). This was incorrect, because of the existence of secondary loggers. To understand why, consider a setup where client code wants internal stderr writes to be redirected to a logger B, while a non-stderr A logger is active. Then the following sequence can occur: - A creates a file. - B creates a file, and redirects internal stderr writes to it. At this point, the behavior is as expected: stderr writes are redirected. - now the code causes A.closeFileLocked() to be called. This causes the call on A to cancel the effects of the redirects on logger B - that is, unwanted "action at a distance". To correct this, this patch only restores the stderr redirect if the logger was also owning the redirection to start with. Furthermore, the entire idea of "redirecting stderr writes to a file" would be a little confusing if two or more loggers had the boolean set to do it. In that case, two loggers could non-deterministically compete to capture stderr when rotating their files alternatively. In order to clarify the API and prevent client code from accidentally relying on this poorly-defined behavior, the patch adds a new method `takeOverInternalStderr()` which enforces the invariant that at most one logger may take over stderr. Finally, for context, be it known that none of the irregularities fixed by this patch are currently impacting the remainder of the CockroachDB code base: `closeFileLocked()` is only called upon `TestLogScope.Close()`, and the previous patches in this sequence have ensured that no stderr is being redirected in the context of a TestLogScope. This patch thus only exists for the benefit of future uses of the API, or readers of the code. Release note: None
- Loading branch information
Showing
5 changed files
with
206 additions
and
37 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
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
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