-
Notifications
You must be signed in to change notification settings - Fork 38.7k
CConnman: move initialization to declaration #20408
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
Conversation
|
cc @practicalswift @MarcoFalke ; related: #20188 (comment) |
maflcko
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.
Seems fine. The alternative would be to call Start in the fuzz tests, but that spins up quite a few threads.
|
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. |
|
review ACK c401a1d83f119f11fe0e446193458c5de224adbf |
|
Is there any downside to just using default initialization for these data members? - uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
+ uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent) {0};
- uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
+ uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent) {0};It seems to me that |
|
Thanks for noticing and fixing this @ajtowns! Any reason not to use in-class member initialisation? Like this: diff --git a/src/net.h b/src/net.h
index 77649247d..d8d7daf64 100644
--- a/src/net.h
+++ b/src/net.h
@@ -478,10 +478,10 @@ private:
uint64_t nTotalBytesSent GUARDED_BY(cs_totalBytesSent) {0};
// outbound limit & stats
- uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent);
- uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent);
- uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent);
- uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent);
+ uint64_t nMaxOutboundTotalBytesSentInCycle GUARDED_BY(cs_totalBytesSent) {0};
+ uint64_t nMaxOutboundCycleStartTime GUARDED_BY(cs_totalBytesSent) {0};
+ uint64_t nMaxOutboundLimit GUARDED_BY(cs_totalBytesSent) {0};
+ uint64_t nMaxOutboundTimeframe GUARDED_BY(cs_totalBytesSent) {0};
// P2P timeout in seconds
int64_t m_peer_connect_timeout;Rationale provided in the C++ Core Guidelines: C.48: Prefer in-class initializers to member initializers in constructors for constant initializers :) |
|
What @jnewbery said literally 4 seconds before me :) |
|
I presumed that the |
Ensure nMaxOutboundTotalBytesSentInCycle and nMaxOutboundCycleStartTime are initialized even if CConnman::Start() is not called.
c401a1d to
9d09132
Compare
|
I think it would be a large change to make it reasonable to call |
|
ACK 9d09132: patch looks correct! |
|
review ACK 9d09132 , checked that we call Start only once and in the same scope where connman is constructed (AppInitMain) 💸 Show signature and timestampSignature: python: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory |
|
Code review ACK 9d09132 |
9d09132 CConnman: initialise at declaration rather than in Start() (Anthony Towns) Pull request description: Ensure nMaxOutboundTotalBytesSentInCycle and nMaxOutboundCycleStartTime are initialized even if CConnman::Start() is not called. Prevents failures in test/fuzz/connman when run under valgrind. ACKs for top commit: practicalswift: ACK 9d09132: patch looks correct! MarcoFalke: review ACK 9d09132 , checked that we call Start only once and in the same scope where connman is constructed (AppInitMain) 💸 jnewbery: Code review ACK 9d09132 Tree-SHA512: 1c6c893e8c616a91947a8cc295b0ba508af3ecfcdcd94cdc5f95d808cc93c6d1a71fd24dcc194dc583854e9889fb522ca8523043367fb0263370fbcab08c6aaa
Summary: Ensure `nMaxOutboundTotalBytesSentInCycle` and `nMaxOutboundCycleStartTime` are initialized even if `CConnman::Start()` is not called. Prevents failures in test/fuzz/connman when run under valgrind. `nTotalBytesRecv` and `nTotalBytesSent` are already initialized in the class definition, and `CConnman::Start` is only called once in `AppInitMain`, so removing the reinitialization in `Start` has no impact. This is a backport of [[bitcoin/bitcoin#20408 | core#20408]] Test Plan: With TSAN: `ninja && ninja check check-functional` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10740
Ensure nMaxOutboundTotalBytesSentInCycle and nMaxOutboundCycleStartTime are initialized even if CConnman::Start() is not called. Prevents failures in test/fuzz/connman when run under valgrind.