fsimpl/host: fix the order of removing FD notifier

FD notifier should be removed before we close the FD,
otherwise there will be race condition that another FD
which has the same value is opened and added before the
existing FD notifier is removed.

Fixes: #3823

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
This commit is contained in:
Tiwei Bie
2020-09-01 16:35:03 +08:00
parent 6748438493
commit d5f20209cc
+1 -1
View File
@@ -348,10 +348,10 @@ func (e *SCMConnectedEndpoint) Init() error {
func (e *SCMConnectedEndpoint) Release(ctx context.Context) {
e.DecRef(func() {
e.mu.Lock()
fdnotifier.RemoveFD(int32(e.fd))
if err := syscall.Close(e.fd); err != nil {
log.Warningf("Failed to close host fd %d: %v", err)
}
fdnotifier.RemoveFD(int32(e.fd))
e.destroyLocked()
e.mu.Unlock()
})