Exposing a port should be idempotent and fix an ephemeral port leak#531
Merged
djs55 merged 9 commits intomoby:masterfrom Apr 27, 2021
Merged
Exposing a port should be idempotent and fix an ephemeral port leak#531djs55 merged 9 commits intomoby:masterfrom
djs55 merged 9 commits intomoby:masterfrom
Conversation
11cab84 to
8b682fe
Compare
We don't need to use `*sync.Mutex` and allocate separately since the nil value works and we are using pointer receivers everywhere. Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
Previously an attempt to expose an identical port would result in an HTTP 500 error. After this patch it results in an HTTP 200. Signed-off-by: David Scott <dave@recoil.org>
This is consistent with the new idempotent semantics. We keep the server POST handlers for backwards compat. Signed-off-by: David Scott <dave@recoil.org>
This is consistent with the existing idempotent semantics. We keep the server POST handlers for backwards compat. Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
If a client requests any port (== 0 i.e. INADDR_ANY) the port is resolved to a concrete port when it is bound. Previously an attempt to list this port and unexpose it would leak because we wouldn't find the concrete port in the map. This patch ensures that the concrete port is stored so the port can be unexposed properly. This also fixes a potential problem where two forwards of any port would only result in one actual forward, because the second one would be assumed to be a duplicate. Signed-off-by: David Scott <dave@recoil.org>
Signed-off-by: David Scott <dave@recoil.org>
0950159 to
dd16d39
Compare
Signed-off-by: David Scott <dave@recoil.org>
dd16d39 to
c8bea32
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 store0in our map, and then look up the real port inUnexposeand fail to find it.To make the API clearer, we switch to
PUTandDELETE(instead ofPOST) but for backwards compatibility retain thePOSThandlers.Minor additional updates:
*sync.Mutextosync.Mutexwhere we are already using a pointer receiver, since thenilvalue is a valid mutexEOFon shutdown)