License #3

Closed
Etherbeard opened this Issue Jan 21, 2014 · 13 comments

Comments

Projects
None yet
9 participants
@Etherbeard

"We will release the source code and settle on a license soon."

What Vitalik said Jan 6, 2014. I guess the LICENSE file is premature or have you already decided?

@gavofyork

This comment has been minimized.

Show comment
Hide comment
@gavofyork

gavofyork Jan 21, 2014

Contributor

Charles mentioned the GNU licences were fine - GPL is my choice.

Thursday, 26 December 2013
[16:29:14] vbuterins: also, for formality's sake, we should nail down the
licenses for all of our open source stuff
[16:29:27] vbuterins: I'll make mine public domain
[16:31:20] Charles Hoskinson: BSD, Apache, MIT
[16:31:33] Charles Hoskinson: You could also use GNU
[16:34:45] Charles Hoskinson: http://opensource.org/licenses
Friday, 27 December 2013
[09:37:17] gavofyork: i've gone with gpl v2

Never put down to incompetence that which can be adequately explained by
self-interest.

On 21 January 2014 05:32, Etherbeard notifications@github.com wrote:

"We will release the source code and settle on a license soon."

What Vitalik said Jan 6, 2014. I guess the LICENSE file is premature or
have you already decided?


Reply to this email directly or view it on GitHubhttps://github.com/ethereum/cpp-ethereum/issues/3
.

Contributor

gavofyork commented Jan 21, 2014

Charles mentioned the GNU licences were fine - GPL is my choice.

Thursday, 26 December 2013
[16:29:14] vbuterins: also, for formality's sake, we should nail down the
licenses for all of our open source stuff
[16:29:27] vbuterins: I'll make mine public domain
[16:31:20] Charles Hoskinson: BSD, Apache, MIT
[16:31:33] Charles Hoskinson: You could also use GNU
[16:34:45] Charles Hoskinson: http://opensource.org/licenses
Friday, 27 December 2013
[09:37:17] gavofyork: i've gone with gpl v2

Never put down to incompetence that which can be adequately explained by
self-interest.

On 21 January 2014 05:32, Etherbeard notifications@github.com wrote:

"We will release the source code and settle on a license soon."

What Vitalik said Jan 6, 2014. I guess the LICENSE file is premature or
have you already decided?


Reply to this email directly or view it on GitHubhttps://github.com/ethereum/cpp-ethereum/issues/3
.

@obscuren

This comment has been minimized.

Show comment
Hide comment
@obscuren

obscuren Jan 21, 2014

Member

GPL is too restrictive imo. Why not just MIT?

Member

obscuren commented Jan 21, 2014

GPL is too restrictive imo. Why not just MIT?

@vbuterin

This comment has been minimized.

Show comment
Hide comment
@vbuterin

vbuterin Jan 21, 2014

Contributor

Agreed. I was going to go with CC zero myself.

On 01/21/2014 01:25 PM, obscuren wrote:

GPL is too restrictive imo. Why not just MIT?


Reply to this email directly or view it on GitHub
#3 (comment).

Contributor

vbuterin commented Jan 21, 2014

Agreed. I was going to go with CC zero myself.

On 01/21/2014 01:25 PM, obscuren wrote:

GPL is too restrictive imo. Why not just MIT?


Reply to this email directly or view it on GitHub
#3 (comment).

@obscuren

This comment has been minimized.

Show comment
Hide comment
@obscuren

obscuren Jan 21, 2014

Member

CC0 goes a little too far for me. I'd much rather go with CCBY

Member

obscuren commented Jan 21, 2014

CC0 goes a little too far for me. I'd much rather go with CCBY

@Etherbeard

This comment has been minimized.

Show comment
Hide comment
@Etherbeard

Etherbeard Jan 21, 2014

CCBY is "Attribution — You must give appropriate credit,"

This has much the same problem as the original, un-revised BSD license.

The MIT license, (or revised BSD, which is the same, really), is very liberal,
while still can not be interpreted as the original author endorsing any
derived work. Also, the MIT license is vetted for software use and will be
familiar for any software IP lawyer. Using the CC licenses for software is
still not very common. I myself has no say in this but I would wish for an
MIT license for maximum adoption of the protocol.

On January 21, 2014 at 8:08 PM obscuren notifications@github.com wrote:

CC0 goes a little too far for me. I'd much rather go with CCBY


Reply to this email directly or view it on GitHub:
#3 (comment)

CCBY is "Attribution — You must give appropriate credit,"

This has much the same problem as the original, un-revised BSD license.

The MIT license, (or revised BSD, which is the same, really), is very liberal,
while still can not be interpreted as the original author endorsing any
derived work. Also, the MIT license is vetted for software use and will be
familiar for any software IP lawyer. Using the CC licenses for software is
still not very common. I myself has no say in this but I would wish for an
MIT license for maximum adoption of the protocol.

On January 21, 2014 at 8:08 PM obscuren notifications@github.com wrote:

CC0 goes a little too far for me. I'd much rather go with CCBY


Reply to this email directly or view it on GitHub:
#3 (comment)

@obscuren

This comment has been minimized.

Show comment
Hide comment
@obscuren

obscuren Jan 21, 2014

Member

I see no problem in giving credit where credit is due. I have no problem choosing MIT over CCBY. I was merely referring that IF I'd have to go with a CC license I'd much rather go with CCBY then CC0. The Go client will get a MIT license.

Member

obscuren commented Jan 21, 2014

I see no problem in giving credit where credit is due. I have no problem choosing MIT over CCBY. I was merely referring that IF I'd have to go with a CC license I'd much rather go with CCBY then CC0. The Go client will get a MIT license.

@kordless

This comment has been minimized.

Show comment
Hide comment
@kordless

kordless Jan 22, 2014

The important part here is code transparency. Any code running in the public space needs to be open and trustworthy. My unmanaged use of that code, off network, is unlikely to matter much to the system itself. It is my belief the GPL is unnecessarily complex for this particular use case and adds risk to adoption. MIT license is the way to role, IMHO.

The important part here is code transparency. Any code running in the public space needs to be open and trustworthy. My unmanaged use of that code, off network, is unlikely to matter much to the system itself. It is my belief the GPL is unnecessarily complex for this particular use case and adds risk to adoption. MIT license is the way to role, IMHO.

@bgw

This comment has been minimized.

Show comment
Hide comment
@bgw

bgw Jan 31, 2014

I know it's not settled yet, but the LICENSE file is GPLv2, while many source files have GPLv3+ comments at the top.

bgw commented Jan 31, 2014

I know it's not settled yet, but the LICENSE file is GPLv2, while many source files have GPLv3+ comments at the top.

@gavofyork

This comment has been minimized.

Show comment
Hide comment
@gavofyork

gavofyork Jan 31, 2014

Contributor

Latest commit fixes the version mismatch.

Kord's point is taken and the licence will be changed to something more
liberal in due course (almost certainly before the first iteration of the
C++ reference client is complete). It's worth remembering that this
codebase is a proof-of-concept prototype, created mainly to test the
whitepaper's premise and verify as reasonable the architecture it asserts.

Never put down to incompetence that which can be adequately explained by
self-interest.

On 31 January 2014 14:56, Benjamin Woodruff notifications@github.comwrote:

I know it's not settled yet, but the LICENSE filehttps://github.com/ethereum/cpp-ethereum/blob/master/LICENSEis GPLv2, while many source files have GPLv3+ comments at the top.

Reply to this email directly or view it on GitHubhttps://github.com/ethereum/cpp-ethereum/issues/3#issuecomment-33836725
.

Contributor

gavofyork commented Jan 31, 2014

Latest commit fixes the version mismatch.

Kord's point is taken and the licence will be changed to something more
liberal in due course (almost certainly before the first iteration of the
C++ reference client is complete). It's worth remembering that this
codebase is a proof-of-concept prototype, created mainly to test the
whitepaper's premise and verify as reasonable the architecture it asserts.

Never put down to incompetence that which can be adequately explained by
self-interest.

On 31 January 2014 14:56, Benjamin Woodruff notifications@github.comwrote:

I know it's not settled yet, but the LICENSE filehttps://github.com/ethereum/cpp-ethereum/blob/master/LICENSEis GPLv2, while many source files have GPLv3+ comments at the top.

Reply to this email directly or view it on GitHubhttps://github.com/ethereum/cpp-ethereum/issues/3#issuecomment-33836725
.

@OmniBazaar

This comment has been minimized.

Show comment
Hide comment
@OmniBazaar

OmniBazaar Jan 31, 2014

MIT license would be fine with me too.

MIT license would be fine with me too.

@nicksavers

This comment has been minimized.

Show comment
Hide comment
@nicksavers

nicksavers Jul 11, 2014

Contributor

Feb 1st, the MIT License has been chosen (commit by Vitalik). See: e10bf35
Unless any changes are planned, I suggest closing this issue.

Contributor

nicksavers commented Jul 11, 2014

Feb 1st, the MIT License has been chosen (commit by Vitalik). See: e10bf35
Unless any changes are planned, I suggest closing this issue.

gavofyork pushed a commit that referenced this issue Oct 3, 2014

@gavofyork

This comment has been minimized.

Show comment
Hide comment
@gavofyork

gavofyork Oct 5, 2014

Contributor

licence is and always has been GPL.

Contributor

gavofyork commented Oct 5, 2014

licence is and always has been GPL.

@gavofyork gavofyork closed this Oct 5, 2014

@vonj

This comment has been minimized.

Show comment
Hide comment
@vonj

vonj Dec 8, 2014

"license is and always has been GPL"

Yet, you Gavin said:

"Kord's point is taken and the licence will be changed to something more liberal in due course", back in January. When is due course?

But now the issue is closed. If you actively want to hinder the adoption of this code, keep the GPL license. Many companies will not take the risk of building their solutions on GPL code, or likely can't even find a business case for it all. If you want to protect the direction of the code, then at least use LGPL. (Though MIT is clearly the simplest license to understand.)

For us GPL is a no go - we would have to use the Go or Python or Java implementation, even though C++ would fit much better.

I understand your point that:
"It's worth remembering that this codebase is a proof-of-concept prototype, created mainly to test the whitepaper's premise and verify as reasonable the architecture it asserts."

However, realistically, probably no one is going to implement a clean room implementation from scratch in C++. If strict clean room principles are employed, the team doing it can't even look at your C++ code, unless they want to use GPL too.

I woke up in the wee hours - couldn't go back to sleep until writing this rant, because it has bugged me since January and now I decided to look back to see if the issue had been resolved.

vonj commented Dec 8, 2014

"license is and always has been GPL"

Yet, you Gavin said:

"Kord's point is taken and the licence will be changed to something more liberal in due course", back in January. When is due course?

But now the issue is closed. If you actively want to hinder the adoption of this code, keep the GPL license. Many companies will not take the risk of building their solutions on GPL code, or likely can't even find a business case for it all. If you want to protect the direction of the code, then at least use LGPL. (Though MIT is clearly the simplest license to understand.)

For us GPL is a no go - we would have to use the Go or Python or Java implementation, even though C++ would fit much better.

I understand your point that:
"It's worth remembering that this codebase is a proof-of-concept prototype, created mainly to test the whitepaper's premise and verify as reasonable the architecture it asserts."

However, realistically, probably no one is going to implement a clean room implementation from scratch in C++. If strict clean room principles are employed, the team doing it can't even look at your C++ code, unless they want to use GPL too.

I woke up in the wee hours - couldn't go back to sleep until writing this rant, because it has bugged me since January and now I decided to look back to see if the issue had been resolved.

CJentzsch added a commit that referenced this issue Dec 16, 2014

subtly added a commit that referenced this issue May 18, 2015

Merge pull request #3 from LefterisJP/wingpu
Pulling subtly's win32 changes from ethash

alexvandesande pushed a commit that referenced this issue Jun 23, 2015

chfast referenced this issue in chfast/cpp-ethereum Aug 16, 2016

Merge pull request #3 from winsvega/gcolvin64
update Block/State/Transaction tests to new block gasLimit 2^63-1

pirapira added a commit that referenced this issue Oct 5, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 6, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 9, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 9, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 10, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 12, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 12, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 13, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 13, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 13, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 16, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 16, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 16, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 16, 2017

Access Host::m_nodeTable using atomic_load and store
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

pirapira added a commit that referenced this issue Oct 16, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 17, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 17, 2017

Access Host::m_nodeTable using atomic_load and store
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

pirapira added a commit that referenced this issue Oct 17, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 18, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 18, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 18, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 18, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 18, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 18, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 18, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 18, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 19, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 19, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 20, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 20, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Avoid using a mutex after it is destroyed
Before this commit, under ThreadSanitizer, this error was visible

WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed) (pid=5256)
    #0 pthread_mutex_lock ??:? (eth+0x48fb60)
    #1 boost::posix::pthread_mutex_lock(pthread_mutex_t*)
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:62 (eth+0x524fb9)
    #2 boost::mutex::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/mutex.hpp:116 (eth+0x524fb9)
    #3 boost::unique_lock<boost::mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:346 (eth+0x524ebe)
    #4 unique_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:124 (eth+0x524c94)
    #5 boost::shared_mutex::lock_shared()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/pthread/shared_mutex.hpp:188 (eth+0x5242cb)
    #6 boost::shared_lock<boost::shared_mutex>::lock()
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:645 (eth+0x5240ce)
    #7 shared_lock
/home/yh/.hunter/_Base/b96750b/af8fb19/497273b/Install/include/boost/thread/lock_types.hpp:520 (eth+0x523c84)
    #8 dev::eth::BlockChain::currentHash() const
/home/yh/src/cpp-ethereum2/libdevcore/../libethereum/BlockChain.h:233 (eth+0x5238a6)
    #9 dev::eth::EthereumHost::doWork()
/home/yh/src/cpp-ethereum2/libethereum/EthereumHost.cpp:433 (eth+0x6c9b0c)
    #10 non-virtual thunk to dev::eth::EthereumHost::doWork() ??:?  (eth+0x6caacd)
    #11 dev::Worker::workLoop()
/home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:139 (eth+0x8507e0)
    #12 operator() /home/yh/src/cpp-ethereum2/libdevcore/Worker.cpp:62 (eth+0x850d3d)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 23, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 23, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 25, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 25, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 25, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9

pirapira added a commit that referenced this issue Oct 29, 2017

Protect Peer::m_score and m_rating under atomic
ThreadSanitizer warned:

WARNING: ThreadSanitizer: data race (pid=12735)
  Read of size 1 at 0x7b3000006b04 by main thread (mutexes: write M1110):
    #0 memcpy ??:? (eth+0x4977d7)
    #1 Peer /home/yh/src/cpp-ethereum/libdevcore/../libp2p/Peer.h:52 (eth+0x833846)
    #2 void __gnu_cxx::new_allocator<std::_List_node<dev::p2p::Peer> >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/new_allocator.h:136 (eth+0x908718)
    #3 void std::allocator_traits<std::allocator<std::_List_node<dev::p2p::Peer> > >::construct<dev::p2p::Peer, dev::p2p::Peer const&>(std::allocator<std::_List_node<dev::p2p::Peer> >&, dev::p2p::Peer*, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/alloc_traits.h:475 (eth+0x908551)
    #4 std::_List_node<dev::p2p::Peer>* std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_create_node<dev::p2p::Peer const&>(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:575 (eth+0x908400)
    #5 void std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::_M_insert<dev::p2p::Peer const&>(std::_List_iterator<dev::p2p::Peer>, dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1801 (eth+0x90834e)
    #6 std::__cxx11::list<dev::p2p::Peer, std::allocator<dev::p2p::Peer> >::push_back(dev::p2p::Peer const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/stl_list.h:1118
(eth+0x8e40eb)

  Previous write of size 4 at 0x7b3000006b04 by thread T30:
    #0 dev::p2p::Session::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Session.cpp:89 (eth+0x951d86)
    #1 dev::p2p::Capability::addRating(int)
/home/yh/src/cpp-ethereum/libp2p/Capability.cpp:59 (eth+0x8c1122)

pirapira added a commit that referenced this issue Oct 29, 2017

Protect m_timer under x_runTimer
For avoiding this warning from ThreadSanitizer:
==================
WARNING: ThreadSanitizer: data race (pid=72207)
  Write of size 8 at 0x7ffca08dd960 by thread T30:
    #0 std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >, std::is_move_constructible<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>, std::is_move_assignable<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*> >::value, void>::type std::swap<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*>(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&, boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*&) /usr/include/c++/7/bits/move.h:199 (eth+0x00000057b9f1)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::reset(boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >*) /usr/include/c++/7/bits/unique_ptr.h:374 (eth+0x00000057b9f1)
    #2 dev::p2p::Host::run(boost::system::error_code const&) /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:665 (eth+0x00000057b9f1)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:720 (eth+0x00000057c426)
    #4 operator() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/bind_handler.hpp:47 (eth+0x00000057c426)
    #5 asio_handler_invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/handler_invoke_hook.hpp:69 (eth+0x00000057c426)
    #6 invoke<boost::asio::detail::binder1<dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)>, boost::system::error_code>, dev::p2p::Host::run(const boost::system::error_code&)::<lambda(const boost::system::error_code&)> > /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37 (eth+0x00000057c426) #7 do_complete /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/wait_handler.hpp:70
(eth+0x00000057c426)
    #8 boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/task_io_service_operation.hpp:38 (eth+0x00000058c145)
    #9 boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:372 (eth+0x00000058c145)
    #10 boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/detail/impl/task_io_service.ipp:149 (eth+0x00000058c145)
    #11 boost::asio::io_service::run() /home/yh/.hunter/_Base/b96750b/a5f7296/9d3cb74/Install/include/boost/asio/impl/io_service.ipp:59 (eth+0x00000057168e)
    #12 dev::p2p::Host::doWork() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:774 (eth+0x00000057168e)
    #13 dev::Worker::workLoop() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:140 (eth+0x0000004a9f64)

  Previous read of size 8 at 0x7ffca08dd960 by main thread:
    #0 std::__uniq_ptr_impl<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::_M_ptr() const /usr/include/c++/7/bits/unique_ptr.h:147 (eth+0x0000005701cd)
    #1 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::get() const /usr/include/c++/7/bits/unique_ptr.h:337 (eth+0x0000005701cd)
    #2 std::unique_ptr<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > >, std::default_delete<boost::asio::basic_deadline_timer<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime>, boost::asio::deadline_timer_service<boost::posix_time::ptime, boost::asio::time_traits<boost::posix_time::ptime> > > > >::operator bool() const /usr/include/c++/7/bits/unique_ptr.h:351 (eth+0x0000005701cd)
    #3 dev::p2p::Host::stop() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:152 (eth+0x0000005701cd)
    #4 dev::WebThreeDirect::~WebThreeDirect() /home/yh/src/cpp-ethereum-vptr/libwebthree/WebThree.cpp:90 (eth+0x000000456f75)
    #5 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:937 (eth+0x0000000c0ff2)

  Location is stack of main thread.

pirapira added a commit that referenced this issue Oct 29, 2017

Protect Host::m_nodeTable with a mutex
For removing the following warning from ThreadSanitizer
==================
WARNING: ThreadSanitizer: data race (pid=68621)
  Write of size 8 at 0x7ffc9f6af3b8 by thread T30:
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator=(std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2> const&) /usr/include/c++/7/bits/shared_ptr_base.h:1034 (eth+0x0000005805bb)
    #1 std::shared_ptr<dev::p2p::NodeTable>::operator=(std::shared_ptr<dev::p2p::NodeTable> const&) /usr/include/c++/7/bits/shared_ptr.h:93 (eth+0x0000005805bb)
    #2 dev::p2p::Host::startedWorking() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:761 (eth+0x0000005805bb)
    #3 operator() /home/yh/src/cpp-ethereum-vptr/libdevcore/Worker.cpp:61 (eth+0x0000004ab343)
    #4 __invoke_impl<void, dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:60 (eth+0x0000004ab6a7)
    #5 __invoke<dev::Worker::startWorking()::<lambda()> > /usr/include/c++/7/bits/invoke.h:95 (eth+0x0000004ab6a7)
    #6 _M_invoke<0> /usr/include/c++/7/thread:234 (eth+0x0000004ab6a7)
    #7 operator() /usr/include/c++/7/thread:243 (eth+0x0000004ab6a7)
    #8 _M_run /usr/include/c++/7/thread:186 (eth+0x0000004ab6a7)
    #9 <null> <null> (libstdc++.so.6+0x0000000bc0fe)

  Previous read of size 8 at 0x7ffc9f6af3b8 by main thread (mutexes:
write M1111):
    #0 std::__shared_ptr<dev::p2p::NodeTable, (__gnu_cxx::_Lock_policy)2>::operator bool() const /usr/include/c++/7/bits/shared_ptr_base.h:1261 (eth+0x0000005716f8)
    #1 dev::p2p::Host::haveNetwork() const /home/yh/src/cpp-ethereum-vptr/libp2p/Host.h:224 (eth+0x0000005716f8)
    #2 dev::p2p::Host::start() /home/yh/src/cpp-ethereum-vptr/libp2p/Host.cpp:129 (eth+0x0000005716f8)
    #3 dev::WebThreeDirect::startNetwork() /home/yh/src/cpp-ethereum-vptr/libdevcore/../libwebthree/WebThree.h:204 (eth+0x0000000bf0d9)
    #4 main /home/yh/src/cpp-ethereum-vptr/eth/main.cpp:1117 (eth+0x0000000bf0d9)

atomic_load and atomic_store work on most tool chains but not on gcc 4.9
https://stackoverflow.com/questions/34205880/why-does-atomic-load-with-a-shared-ptr-not-compile-with-gcc-4-9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment