mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
Make ReqInfo concurrency safe (#15204)
Some read/writes of ReqInfo did not get appropriate locks, leading to races. Make sure reading and writing holds appropriate locks.
This commit is contained in:
@@ -149,7 +149,6 @@ func GetAuditEntry(ctx context.Context) *audit.Entry {
|
||||
DeploymentID: xhttp.GlobalDeploymentID,
|
||||
Time: time.Now().UTC(),
|
||||
}
|
||||
SetAuditEntry(ctx, r)
|
||||
return r
|
||||
}
|
||||
return nil
|
||||
@@ -168,6 +167,8 @@ func AuditLog(ctx context.Context, w http.ResponseWriter, r *http.Request, reqCl
|
||||
if reqInfo == nil {
|
||||
return
|
||||
}
|
||||
reqInfo.RLock()
|
||||
defer reqInfo.RUnlock()
|
||||
|
||||
entry = audit.ToEntry(w, r, reqClaims, xhttp.GlobalDeploymentID)
|
||||
// indicates all requests for this API call are inbound
|
||||
|
||||
@@ -290,6 +290,8 @@ func errToEntry(ctx context.Context, err error, errKind ...interface{}) log.Entr
|
||||
if req == nil {
|
||||
req = &ReqInfo{API: "SYSTEM"}
|
||||
}
|
||||
req.RLock()
|
||||
defer req.RUnlock()
|
||||
|
||||
API := "SYSTEM"
|
||||
if req.API != "" {
|
||||
|
||||
@@ -41,6 +41,7 @@ type ObjectVersion struct {
|
||||
}
|
||||
|
||||
// ReqInfo stores the request info.
|
||||
// Reading/writing directly to struct requires appropriate R/W lock.
|
||||
type ReqInfo struct {
|
||||
RemoteHost string // Client Host/IP
|
||||
Host string // Node Host/IP
|
||||
@@ -111,7 +112,7 @@ func (r *ReqInfo) GetTags() []KeyVal {
|
||||
}
|
||||
r.RLock()
|
||||
defer r.RUnlock()
|
||||
return append([]KeyVal(nil), r.tags...)
|
||||
return append(make([]KeyVal, 0, len(r.tags)), r.tags...)
|
||||
}
|
||||
|
||||
// GetTagsMap - returns the user defined tags in a map structure
|
||||
@@ -145,7 +146,6 @@ func GetReqInfo(ctx context.Context) *ReqInfo {
|
||||
return r
|
||||
}
|
||||
r = &ReqInfo{}
|
||||
SetReqInfo(ctx, r)
|
||||
return r
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user