From 58cc13ab291cac5b13462006e3feb780178ef5f3 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Fri, 10 Apr 2020 16:21:58 +0300 Subject: Resolving a racing condition while adding ports on the app's side. An earlier attempt (ad6265786871) to resolve this condition on the router's side added a new issue: the app could get a request before acquiring a port. --- go/port.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'go') diff --git a/go/port.go b/go/port.go index 72d33d31..59a13f8b 100644 --- a/go/port.go +++ b/go/port.go @@ -50,7 +50,11 @@ func add_port(p *port) { port_registry_.m = make(map[port_key]*port) } - port_registry_.m[p.key] = p + old := port_registry_.m[p.key] + + if old == nil { + port_registry_.m[p.key] = p + } port_registry_.Unlock() } -- cgit