Previously attempting to expose an existing port would return an error, which becomes an HTTP 500 internal server error.
This patch makes exposing a port idempotent, just like un-exposing a port already is.
Previously there was a port leak if the user requested any port (0) because we would store 0 in our map, and then look up the real port in Unexpose and fail to find it.
To make the API clearer, we switch to PUT and DELETE (instead of POST) but for backwards compatibility retain the POST handlers.
Minor additional updates:
switch from *sync.Mutex to sync.Mutex where we are already using a pointer receiver, since the nil value is a valid mutex
run the unit tests with the race detector enabled
avoid logging as errors 3 expected conditions (all variations of an EOF on shutdown)
Previously attempting to expose an existing port would return an error, which becomes an HTTP 500 internal server error.
This patch makes exposing a port idempotent, just like un-exposing a port already is.
Previously there was a port leak if the user requested any port (
0
) because we would store0
in our map, and then look up the real port inUnexpose
and fail to find it.To make the API clearer, we switch to
PUT
andDELETE
(instead ofPOST
) but for backwards compatibility retain thePOST
handlers.Minor additional updates:
*sync.Mutex
tosync.Mutex
where we are already using a pointer receiver, since thenil
value is a valid mutexEOF
on shutdown)