Commit fe141f38 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fuse: increment loops WaitGroup on Server creation

The server.Serve routine can be called both inline and as
goroutine. In the latter case, it is a synchronization error for Serve
to call serve.loops.Add() by itself, leading to a detected race.

Change-Id: I36f24bd36d1ae77d71e7d69a54ebdf5dbee9bd62
parent 0e3c45fc
...@@ -202,6 +202,10 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -202,6 +202,10 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
// TODO - unmount as well? // TODO - unmount as well?
return nil, fmt.Errorf("init: %s", code) return nil, fmt.Errorf("init: %s", code)
} }
// This prepares for Serve being called somewhere, either
// synchronously or asynchronously.
ms.loops.Add(1)
return ms, nil return ms, nil
} }
...@@ -360,7 +364,6 @@ func (ms *Server) recordStats(req *request) { ...@@ -360,7 +364,6 @@ func (ms *Server) recordStats(req *request) {
// //
// Each filesystem operation executes in a separate goroutine. // Each filesystem operation executes in a separate goroutine.
func (ms *Server) Serve() { func (ms *Server) Serve() {
ms.loops.Add(1)
ms.loop(false) ms.loop(false)
ms.loops.Wait() ms.loops.Wait()
...@@ -386,7 +389,8 @@ func (ms *Server) Serve() { ...@@ -386,7 +389,8 @@ func (ms *Server) Serve() {
} }
} }
// Wait waits for the serve loop to exit // Wait waits for the serve loop to exit. This should only be called
// after Serve has been called, or it will hang indefinitely.
func (ms *Server) Wait() { func (ms *Server) Wait() {
ms.loops.Wait() ms.loops.Wait()
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment