datarhei / gosrt

Implementation of the SRT protocol in pure Go
https://datarhei.com
MIT License
98 stars 15 forks source link

fix data race in sendNAK() #19

Closed aler9 closed 11 months ago

aler9 commented 11 months ago

Hello, sendNACK() is called by both recv.Tick() and recv.Push() in two separate routines, the operation pktSentNAK++ is not atomic (it gets compiled into a read command followed by a write command) and must be protected.

ioppermann commented 11 months ago

Thanks for pointing this out. All the writes to the statistics must be protected because of the conn.Stats() function which is reading the statistics. In datarhei/gosrt@da138d1 I introduced a dedicated lock for the statistics. Using the c.cryptoLock is confusing.

aler9 commented 11 months ago

A dedicated lock is the best option, i didn't do it because i did not want to add additional resources without a good reason.