Skip to content

Commit

Permalink
removed readlock on copied map item
Browse files Browse the repository at this point in the history
  • Loading branch information
k4lizen committed Jul 31, 2023
1 parent f9d65c8 commit e51c0a7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/rank/rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import (
"github.com/tminaorg/brzaguza/src/structures"
)

// only one call for setResultResponse for a page will ever be performed, so there will never be a read and a write to result.Response at the same time
// thus not locking relay.ResultMap[result.URL] in this function, because the result parameter is a copy is safe. It may, however, read memory that the map sees,
// at the same time that the map is being written to, while this should be fine in this use-case, go may throw an error.
// TLDR: you must mutex.Lock when changing *rankAddr, you probably dont need to mutex.RLock() when reading result
// (in reality even *rankAddr shouldnt need a lock, but go would definately complain about simultanious read/write because of it)
func SetRank(result *structures.Result, rankAddr *int, mutex *sync.RWMutex) {

mutex.RLock()
reqUrl := result.Response.Request.URL.String() //dummy code
mutex.RUnlock()
//mutex.RLock()
reqUrl := result.Response.Request.URL.String() //dummy code, if error here, uncomment lock
//mutex.RUnlock()

if reqUrl != result.URL { //dummy code
log.Trace().Msg("Request URL not same as result.URL \\/")
Expand Down

0 comments on commit e51c0a7

Please sign in to comment.