-
Notifications
You must be signed in to change notification settings - Fork 38.7k
util: Log early messages #16112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util: Log early messages #16112
Conversation
fab38de to
fa9bc80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK fa9bc80, I don't see a problem regarding the new circular dependency.
fa10f8b to
faaba72
Compare
It would lead to issues in debug builds when a potential deadlock was detected, so I've reverted that for now. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
hebasto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
StartLogging() is used to mark the start of logging generically, whether using -printtoconsole or -debuglogfile.
This ensures log messages prior to StartLogging() are replayed to the console as well as to the debug log file.
|
Concept ACK |
|
Is there any reason to buffer the writing to |
If you have |
|
I've done #16127 to see what it would take to keep the thread safety annotations without the dependency loop (and hopefully also without the bugs), and what it'd look like to do the same thing elsewhere. Seems better to do that later (or not at all) than to add it to this PR to me... |
|
utACK faa2a47 |
kristapsk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK faa2a47 (ran added functional test before / after recompiling, didn't do additional testing)
|
@MarcoFalke, why buffer also the writing to
|
|
Unless there are objections, this will be merged tomorrow |
Going to test in a few hours. |
|
ACK faa2a47 Tested on Linux Mint 19.1:
Nit: could the test for Line 864 in 8ab4f28
be added? |
faa2a47 logging: Add threadsafety comments (MarcoFalke) 0b282f9 Log early messages with -printtoconsole (Anthony Towns) 4129874 Replace OpenDebugLog() with StartLogging() (Anthony Towns) Pull request description: Early log messages are dropped on the floor and they'd never make it to the console or debug log. This can be tested by running the test included in this pull request without re-compiling the `bitcoind`. Fix that by buffering early messages and flushing them as soon as all logging options have been initialized and logging has been started. This pull request is identical to "Log early messages with -printtoconsole" (#13088) by **ajtowns**, with the following changes: * Rebased * Added docstrings for `m_buffering` and `StartLogging` * Switch `CCriticalSection` (aka `RecursiveMutex`) to just `Mutex` in the last commit * Added tests Fixes #16098 Fixes #13157 Closes #13088 ACKs for commit faa2a4: ajtowns: utACK faa2a47 hebasto: ACK faa2a47 kristapsk: ACK faa2a47 (ran added functional test before / after recompiling, didn't do additional testing) Tree-SHA512: 685e2882642fe2a43ce171d42862582dadb840d03cda8236a994322c389ca2a1f3f431b179b2726c155c61793543bb340c568a5455d97f8b83bc7d307a85d387
faa2a47 logging: Add threadsafety comments (MarcoFalke) 0b282f9 Log early messages with -printtoconsole (Anthony Towns) 4129874 Replace OpenDebugLog() with StartLogging() (Anthony Towns) Pull request description: Early log messages are dropped on the floor and they'd never make it to the console or debug log. This can be tested by running the test included in this pull request without re-compiling the `bitcoind`. Fix that by buffering early messages and flushing them as soon as all logging options have been initialized and logging has been started. This pull request is identical to "Log early messages with -printtoconsole" (bitcoin#13088) by **ajtowns**, with the following changes: * Rebased * Added docstrings for `m_buffering` and `StartLogging` * Switch `CCriticalSection` (aka `RecursiveMutex`) to just `Mutex` in the last commit * Added tests Fixes bitcoin#16098 Fixes bitcoin#13157 Closes bitcoin#13088 ACKs for commit faa2a4: ajtowns: utACK faa2a47 hebasto: ACK faa2a47 kristapsk: ACK faa2a47 (ran added functional test before / after recompiling, didn't do additional testing) Tree-SHA512: 685e2882642fe2a43ce171d42862582dadb840d03cda8236a994322c389ca2a1f3f431b179b2726c155c61793543bb340c568a5455d97f8b83bc7d307a85d387
Summary: ``` Early log messages are dropped on the floor and they'd never make it to the console or debug log. This can be tested by running the test included in this pull request without re-compiling the bitcoind. Fix that by buffering early messages and flushing them as soon as all logging options have been initialized and logging has been started. ``` Backport of core [[bitcoin/bitcoin#16112 | PR16112]]. Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D5553
5478d6c logging: thread safety annotations (Anthony Towns) e685ca1 util/system.cpp: add thread safety annotations for dir_locks (Anthony Towns) a788789 test/checkqueue_tests: thread safety annotations (Anthony Towns) 479c584 rpc/blockchain.cpp: thread safety annotations for latestblock (Anthony Towns) 8b5af3d net: fMsgProcWake use LOCK instead of lock_guard (Anthony Towns) de7c5f4 wallet/wallet.h: Remove mutexScanning which was only protecting a single atomic bool (Anthony Towns) c3cf2f5 rpc/blockchain.cpp: Remove g_utxosetscan mutex that is only protecting a single atomic variable (Anthony Towns) Pull request description: In a few cases we need to use `std::mutex` rather than the sync.h primitives. But `std::lock_guard<std::mutex>` doesn't include the clang thread safety annotations unless you also use clang's C library, which means you can't indicate when variables should be guarded by `std::mutex` mutexes. This adds an annotated version of `std::lock_guard<std::mutex>` to threadsafety.h to fix that, and modifies places where `std::mutex` is used to take advantage of the annotations. It's based on top of #16112, and turns the thread safety comments included there into annotations. It also changes the RAII classes in wallet/wallet.h and rpc/blockchain.cpp to just use the atomic<bool> flag for synchronisation rather than having a mutex that doesn't actually guard anything as well. ACKs for top commit: MarcoFalke: ACK 5478d6c 🗾 hebasto: re-ACK 5478d6c, only renamed s/`MutexGuard`/`LockGuard`/, and dropped the commit "test/util_threadnames_tests: add thread safety annotations" since the [previous](#16127 (review)) review. ryanofsky: Code review ACK 5478d6c. Thanks for taking suggestions! Only changes since last review are dropping thread rename test commit d53072ec730d8eec5a5b72f7e65a54b141e62b19 and renaming mutex guard to lock guard Tree-SHA512: 7b00d31f6f2b5a222ec69431eb810a74abf0542db3a65d1bbad54e354c40df2857ec89c00b4a5e466c81ba223267ca95f3f98d5fbc1a1d052a2c3a7d2209790a
5478d6c logging: thread safety annotations (Anthony Towns) e685ca1 util/system.cpp: add thread safety annotations for dir_locks (Anthony Towns) a788789 test/checkqueue_tests: thread safety annotations (Anthony Towns) 479c584 rpc/blockchain.cpp: thread safety annotations for latestblock (Anthony Towns) 8b5af3d net: fMsgProcWake use LOCK instead of lock_guard (Anthony Towns) de7c5f4 wallet/wallet.h: Remove mutexScanning which was only protecting a single atomic bool (Anthony Towns) c3cf2f5 rpc/blockchain.cpp: Remove g_utxosetscan mutex that is only protecting a single atomic variable (Anthony Towns) Pull request description: In a few cases we need to use `std::mutex` rather than the sync.h primitives. But `std::lock_guard<std::mutex>` doesn't include the clang thread safety annotations unless you also use clang's C library, which means you can't indicate when variables should be guarded by `std::mutex` mutexes. This adds an annotated version of `std::lock_guard<std::mutex>` to threadsafety.h to fix that, and modifies places where `std::mutex` is used to take advantage of the annotations. It's based on top of bitcoin#16112, and turns the thread safety comments included there into annotations. It also changes the RAII classes in wallet/wallet.h and rpc/blockchain.cpp to just use the atomic<bool> flag for synchronisation rather than having a mutex that doesn't actually guard anything as well. ACKs for top commit: MarcoFalke: ACK 5478d6c 🗾 hebasto: re-ACK 5478d6c, only renamed s/`MutexGuard`/`LockGuard`/, and dropped the commit "test/util_threadnames_tests: add thread safety annotations" since the [previous](bitcoin#16127 (review)) review. ryanofsky: Code review ACK 5478d6c. Thanks for taking suggestions! Only changes since last review are dropping thread rename test commit d53072ec730d8eec5a5b72f7e65a54b141e62b19 and renaming mutex guard to lock guard Tree-SHA512: 7b00d31f6f2b5a222ec69431eb810a74abf0542db3a65d1bbad54e354c40df2857ec89c00b4a5e466c81ba223267ca95f3f98d5fbc1a1d052a2c3a7d2209790a
merge bitcoin#11640, bitcoin#11599, bitcoin#16112, bitcoin#16127, bitcoin#18635, bitcoin#19249: thread safety and locking improvements
Early log messages are dropped on the floor and they'd never make it to the console or debug log. This can be tested by running the test included in this pull request without re-compiling the
bitcoind.Fix that by buffering early messages and flushing them as soon as all logging options have been initialized and logging has been started.
This pull request is identical to "Log early messages with -printtoconsole" (#13088) by ajtowns, with the following changes:
m_bufferingandStartLoggingCCriticalSection(akaRecursiveMutex) to justMutexin the last commitFixes #16098
Fixes #13157
Closes #13088