trezor / trezord-go

:smiling_imp: Trezor Communication Daemon (written in Go)
GNU Lesser General Public License v3.0
244 stars 146 forks source link

Lock sessionsMutex when deleting session #191

Closed tsusanka closed 4 years ago

tsusanka commented 4 years ago

When built with -race, running acquire and then:

echo -n "001400000000" | http -v POST "127.0.0.1:21325/call/2"

(001400000000 is just an example of Cancel message, http command is httpie, use whatever you want.)

following with a release command:

http -v POST "127.0.0.1:21325/release/2"

I am receiving a race condition warning as mentioned in https://github.com/trezor/trezord-go/issues/190#issuecomment-627142657. I believe that in some rare cases this could have led to a crash when two concurrent writes actually happened? In @mroz22's case (see the issue) it was concurrent iteration and write, so my guess is it was Acquire's findPrevSession and Release's delete.


This PR adds sessionsMutex lock to release so the calls are separated. Running the test case above does not show the warning anymore.

Fixes #190