RecordBytesSent() does not require cs_vSend to be locked, so reduce the scope of cs_vSend.
Also correctly annotate the CNode data members that are guarded by cs_vSend.
This is a simpler alternative to #19673.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, 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.
Concept ACK
Thanks for improving locking!
1522- if (nBytes) {
1523- RecordBytesSent(nBytes);
1524- }
1525+ if (sendSet) {
1526+ // Send data
1527+ size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, {return SocketSendData(pnode);});
stylistic yocto-nit: could drop the curly braces for the lambda argument here – according to git grep WITH_LOCK.*return
on all other places the code is directly passed, w/o putting in a block.
0 size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
OTOH maybe the way in this PR is preferred and the others should be adapted (though not in this PR, obviously), IDK.
1521- size_t nBytes = SocketSendData(pnode);
1522- if (nBytes) {
1523- RecordBytesSent(nBytes);
1524- }
1525+ if (sendSet) {
1526+ // Send data
1522- if (nBytes) {
1523- RecordBytesSent(nBytes);
1524- }
1525+ if (sendSet) {
1526+ // Send data
1527+ size_t bytes_sent = WITH_LOCK(pnode->cs_vSend, return SocketSendData(pnode));
same commit: The lock annotation for this member function SocketSendData
is in the wrong place. Should be in the h file not the cpp file because otherwise moving code can disable the annotation.
Would be nice to fix in this pull and maybe also update the SocketSendData
pointer arg to a reference?
review ACK 378aedc45248cea82d9a3e6dc1038d6828008a76 🔌
Signature:
0-----BEGIN PGP SIGNED MESSAGE-----
1Hash: SHA512
2
3review ACK 378aedc45248cea82d9a3e6dc1038d6828008a76 🔌
4-----BEGIN PGP SIGNATURE-----
5
6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
7pUh/bAwAlAViNkPZb/+MFuod/2ZmdPPu+12UtIpBh3oTcEKw+G/wdVHJ7fCPI7Tv
8yvd8cPzeOKp3dXSqsuTu6UOHJ9+mcRodOkiu9F6smvgo0NLIC+DKYFUoRD8ywaEN
92GhjFdiIKJoaDPRLM+YA3FEVbJG1oxqUX6ifnlk/Zyh+/zCLd5l4S3GqcLQmhyJ/
104guvd1eq9a4H1apiGEop3j75Xm+jFvou07WF31RJgJgmP9L3WELsYItcpLe7+Gar
11nVhL6amBwh4Ctt2DYcggNhP3mk/a6bOSvYVBDOAlfya4SOlg1weBXwjU1o1jpv2C
12X5HgiToUfl4UzlYoFz7kxPoFJHCMhgaTadL23IiJpf5Tm/nNX/NVcJbTf5+WRUfd
13ns/enM8FESK7cp4z4qwnOk1EY5tfHhrGTnXx36GaVyABggL/TaObMxrGZbxjBiPx
14T8wByTCoTUdpXHjtqloT3AzLoJq8uTRJQlyd5WyqPjQbn75hcBij1JmprCD6KoUo
15CAf3cVsZ
16=tcoi
17-----END PGP SIGNATURE-----
Timestamp of file with hash df2bf40ec7e87ed6608ff1eeaa002645df088c8901feef602a141b1ef0909d5f -
let me know if you want this merged or address the style nits
I’ll address your review comments. Might as well fix those things up while I’m touching this code.
CI is failing now:
0In file included from net.cpp:10:
1./net.h:451:77: error: member access into incomplete type 'CNode'
2 size_t SocketSendData(CNode& pnode) const EXCLUSIVE_LOCKS_REQUIRED(pnode.cs_vSend);
3 ^
4./net.h:39:7: note: forward declaration of 'CNode'
5class CNode;
6 ^
71 error generated.
ACK 378aedc45248cea82d9a3e6dc1038d6828008a76
This is definitely the right way to fix this.