fix(logging): scope logRotator state per instance - #1175
Merged
Conversation
`lastRotationTime` and `setIntervalId` were module-level. After #1111 fixed the broken require so harper_logger.getFileLogger actually creates rotators, multiple rotators can exist concurrently (e.g. for http logger, external logger, hdb logger). Every new rotator call overwrites the shared `setIntervalId`, so `rotator.end()` on any instance clears the most-recently-created interval — not its own. This surfaced as a unit-test regression: the harper_logger HTTP and global-logger tests trigger lingering setTimeouts (from the `path =` setter calling getFileLogger) that fire ~100ms later. When the logRotator test then created its rotator, the lingering setTimeouts called `logger.rotator?.end()` -> `clearInterval(module-level setIntervalId)`, which clobbered the test's interval. The rotation never fired and `getLastRotatedLogPath()` returned undefined. Move both variables into the function closure so each rotator owns its own state and `end()` only clears its own interval. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
|
Reviewed; no blockers found. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
utility/logging/logRotator.tsdeclaredlastRotationTimeandsetIntervalIdat module scope, so everylogRotator()call overwrote the shared id. Once #1111 fixed the brokenrequireandharper_logger.getFileLoggerstarted creating real rotators, multiple instances (hdb, http, external) could coexist and anyrotator.end()wouldclearIntervalthe most-recently-created interval instead of its own.Move both into the function closure so each rotator owns its state.
Regression context
Before #1111,
harper_logger.getFileLogger's internalrequire('./logRotator')()threw a TypeError (it was getting the CJS namespace object, not the function) and was swallowed by acatch, so log rotation was silently disabled and the module-level state was only ever touched by direct callers (e.g. the unit test). #1111 fixed the require, exposing the latent state-sharing bug.The unit-test failure mode after #1111:
harper_logger.test.jsHTTP/global-loggerafter()hooks reassignhttpLogger.path/externalLogger.path, which schedules a 100mssetTimeoutingetFileLoggerthat callslogger.rotator?.end(). Thatend()resolves toclearInterval(module-level setIntervalId)— clobbering the logRotator unit test's own interval that was just created, so rotation never fires andgetLastRotatedLogPath()returnsundefined.Verification
npm run test:unit:logging-> 49 passing (was 1 failing).npm run test:unit:main-> the 5 remaining failures are pre-existing SQL Engine / analytics serialization / scopedImport issues unrelated to logging.Generated by Claude Opus 4.7.