mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-18 21:26:56 +00:00
fix(ec): take ecjFileAccessLock before the nil-check in Sync and Close
Sync and Close read ev.ecjFile before acquiring ecjFileAccessLock while Close nils it under the lock, a data race on the field. Take the lock first, then nil-check inside, in both.
This commit is contained in:
@@ -232,12 +232,12 @@ func (ev *EcVolume) Close() {
|
||||
for _, s := range ev.Shards {
|
||||
s.Close()
|
||||
}
|
||||
ev.ecjFileAccessLock.Lock()
|
||||
if ev.ecjFile != nil {
|
||||
ev.ecjFileAccessLock.Lock()
|
||||
_ = ev.ecjFile.Close()
|
||||
ev.ecjFile = nil
|
||||
ev.ecjFileAccessLock.Unlock()
|
||||
}
|
||||
ev.ecjFileAccessLock.Unlock()
|
||||
if ev.ecxFile != nil {
|
||||
_ = ev.ecxFile.Sync()
|
||||
// Do NOT nil ecxFile: LocateEcShardNeedle reads it without the
|
||||
@@ -252,13 +252,13 @@ func (ev *EcVolume) Close() {
|
||||
// This ensures that deletions made via DeleteNeedleFromEcx are visible
|
||||
// to other processes/file handles that may read these files.
|
||||
func (ev *EcVolume) Sync() {
|
||||
ev.ecjFileAccessLock.Lock()
|
||||
if ev.ecjFile != nil {
|
||||
ev.ecjFileAccessLock.Lock()
|
||||
if err := ev.ecjFile.Sync(); err != nil {
|
||||
glog.Warningf("failed to sync ecj file for volume %d: %v", ev.VolumeId, err)
|
||||
}
|
||||
ev.ecjFileAccessLock.Unlock()
|
||||
}
|
||||
ev.ecjFileAccessLock.Unlock()
|
||||
if ev.ecxFile != nil {
|
||||
if err := ev.ecxFile.Sync(); err != nil {
|
||||
glog.Warningf("failed to sync ecx file for volume %d: %v", ev.VolumeId, err)
|
||||
|
||||
Reference in New Issue
Block a user