mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
Fix race in checkServerTime
This commit is contained in:
parent
cc4f5ba7ba
commit
5454f2abd0
10
fs/http.go
10
fs/http.go
@ -143,6 +143,9 @@ func NewTransport(transport *http.Transport, logHeader, logBody bool) *Transport
|
||||
}
|
||||
}
|
||||
|
||||
// A mutex to protect this map
|
||||
var checkedHostMu sync.RWMutex
|
||||
|
||||
// A map of servers we have checked for time
|
||||
var checkedHost = make(map[string]struct{}, 1)
|
||||
|
||||
@ -152,7 +155,10 @@ func checkServerTime(req *http.Request, resp *http.Response) {
|
||||
if req.Host != "" {
|
||||
host = req.Host
|
||||
}
|
||||
if _, ok := checkedHost[host]; ok {
|
||||
checkedHostMu.RLock()
|
||||
_, ok := checkedHost[host]
|
||||
checkedHostMu.RUnlock()
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
dateString := resp.Header.Get("Date")
|
||||
@ -169,7 +175,9 @@ func checkServerTime(req *http.Request, resp *http.Response) {
|
||||
if dt > window || dt < -window {
|
||||
Log(nil, "Time may be set wrong - time from %q is %v different from this computer", host, dt)
|
||||
}
|
||||
checkedHostMu.Lock()
|
||||
checkedHost[host] = struct{}{}
|
||||
checkedHostMu.Unlock()
|
||||
}
|
||||
|
||||
// RoundTrip implements the RoundTripper interface.
|
||||
|
Loading…
Reference in New Issue
Block a user