This PR tries to fix #92, by locking access to the Mirrorlist's Urls during refresh.
I had the same problem on my deployed pacoloco and also successfully reproduced the issue using @chennin's script. Using this PR, both were unable to reproduce the error on my system.
I'm new to go and it's concurrency model, but my guess is that the repo archlinux has no urls error happens due to a race condition in getMirrorlistURLs():
While the Mirrorlist File is read for the first time (e.g. because of a request for 'core.db') the URLs array is still empty but LastMirrorlistCheck is already set. When in this moment the function is called concurrently (e.g. because of a parallel download request for 'extra.db') it returns the still empty URLs array due to a recent LastMirrorlistCheck, instead of waiting for it to be populated.
I used a mutex instead of setting the LastMirrorlistCheck after URLs is populated to block multiple goroutines from reading and parsing the same Mirrorlist simultaneously.
However this doesn't fix any possible racing with reflector or similar.
Would love for someone to try reproducing #92 with this PR on their system and review my first work with go.
This PR tries to fix #92, by locking access to the Mirrorlist's Urls during refresh.
I had the same problem on my deployed
pacoloco
and also successfully reproduced the issue using @chennin's script. Using this PR, both were unable to reproduce the error on my system.I'm new to go and it's concurrency model, but my guess is that the
repo archlinux has no urls
error happens due to a race condition ingetMirrorlistURLs()
: While the Mirrorlist File is read for the first time (e.g. because of a request for 'core.db') theURLs
array is still empty butLastMirrorlistCheck
is already set. When in this moment the function is called concurrently (e.g. because of a parallel download request for 'extra.db') it returns the still emptyURLs
array due to a recentLastMirrorlistCheck
, instead of waiting for it to be populated.I used a mutex instead of setting the
LastMirrorlistCheck
afterURLs
is populated to block multiple goroutines from reading and parsing the same Mirrorlist simultaneously. However this doesn't fix any possible racing withreflector
or similar.Would love for someone to try reproducing #92 with this PR on their system and review my first work with go.