lnobad / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

NetSha thread safety #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
NetSha.Hash method isn't thread safe. (I have got the CryptographicException)
Although it is protected in NetPeer.Internal with lock , two NetPeers can call 
this method simultaneously.

Moreover according to MSDN ( 
http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx  
)
"Any public static (Shared in Visual Basic) members of this type are thread 
safe. Any instance members are not guaranteed to be thread safe."

ComputeHash is an instance method, therefore not thread safe.

Solution:
Since this method is needed primarily in NetPeer.InitializeNetwork which is 
called only once per NetPeer, this method can be surrounded with simple lock.

Original issue reported on code.google.com by NN1436401@gmail.com on 26 Sep 2010 at 11:01

GoogleCodeExporter commented 9 years ago
Good idea. Fixed in revision 124

Original comment by lidg...@gmail.com on 26 Sep 2010 at 1:17

GoogleCodeExporter commented 9 years ago

Original comment by lidg...@gmail.com on 26 Sep 2010 at 1:17