add locks to avoid possible race condition using command port #2

Merged
sarah merged 1 commits from locks2 into master 2020-05-08 23:33:17 +00:00
1 changed files with 4 additions and 0 deletions

View File

@ -87,7 +87,9 @@ func (tp *torProvider) GetBootstrapStatus() (int, string) {
return -1, "Network Down" return -1, "Network Down"
} }
tp.lock.Lock()
kvs, err := tp.t.Control.GetInfo("status/bootstrap-phase") kvs, err := tp.t.Control.GetInfo("status/bootstrap-phase")
tp.lock.Unlock()
if err != nil { if err != nil {
return -2, "error querrying status/bootstrap-phase" return -2, "error querrying status/bootstrap-phase"
} }
@ -122,6 +124,8 @@ func (tp *torProvider) WaitTillBootstrapped() {
// getNetworkStatus returns tor's beleif in the underlying network's status // getNetworkStatus returns tor's beleif in the underlying network's status
func (tp *torProvider) getNetworkStatus() int { func (tp *torProvider) getNetworkStatus() int {
tp.lock.Lock()
defer tp.lock.Unlock()
if tp.t == nil { if tp.t == nil {
return networkDown return networkDown
} }