fix race in UIserver
This commit is contained in:
parent
8b861245c0
commit
f9812d3ef8
1 changed files with 5 additions and 0 deletions
|
@ -57,6 +57,7 @@ type NetUI struct {
|
||||||
workers []Worker
|
workers []Worker
|
||||||
workersMutex sync.Mutex
|
workersMutex sync.Mutex
|
||||||
sock *net.Listener
|
sock *net.Listener
|
||||||
|
sockMu sync.Mutex
|
||||||
exit chan interface{}
|
exit chan interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +96,8 @@ func (n *NetUI) Update() {
|
||||||
|
|
||||||
// Close shuts the TCPserver down synchronously
|
// Close shuts the TCPserver down synchronously
|
||||||
func (n *NetUI) Close() {
|
func (n *NetUI) Close() {
|
||||||
|
n.sockMu.Lock()
|
||||||
|
defer n.sockMu.Unlock()
|
||||||
if n.sock != nil {
|
if n.sock != nil {
|
||||||
(*n.sock).Close()
|
(*n.sock).Close()
|
||||||
}
|
}
|
||||||
|
@ -141,7 +144,9 @@ func (n *NetUI) Run(sock net.Listener) error {
|
||||||
if n.sock != nil {
|
if n.sock != nil {
|
||||||
return fmt.Errorf("More than one Run for a single NetUI is currently unsupported")
|
return fmt.Errorf("More than one Run for a single NetUI is currently unsupported")
|
||||||
}
|
}
|
||||||
|
n.sockMu.Lock()
|
||||||
n.sock = &sock
|
n.sock = &sock
|
||||||
|
n.sockMu.Unlock()
|
||||||
defer sock.Close()
|
defer sock.Close()
|
||||||
for {
|
for {
|
||||||
conn, err := sock.Accept()
|
conn, err := sock.Accept()
|
||||||
|
|
Loading…
Reference in a new issue