From 8b72cfa63f1b7b305cd3a4d4d9b7aa7c16e8b69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Mon, 11 Jul 2022 13:25:17 +0200 Subject: [PATCH] Add comment explaining error handling in removeGateway Edoardo asked about it some time ago. I forgot to add the explanation to the code. https://github.com/gravitational/teleport/pull/14135#discussion_r914687662 --- lib/teleterm/daemon/daemon.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/teleterm/daemon/daemon.go b/lib/teleterm/daemon/daemon.go index 02b48d17bf3e8..1791259432ef2 100644 --- a/lib/teleterm/daemon/daemon.go +++ b/lib/teleterm/daemon/daemon.go @@ -184,6 +184,14 @@ func (s *Service) RemoveGateway(gatewayURI string) error { // removeGateway assumes that mu is already held by a public method. func (s *Service) removeGateway(gateway *gateway.Gateway) error { + // In case closing the gateway fails, we want to return early and leave the gateway in the map. + // + // This way the gateway will remain shown as available in the app. The user will see the error + // related to closing the gateway and will be able to attempt to close it again. + // + // This is preferable to removing the gateway from the hash map. Since Connect remembers the port + // used for a particular db server + username pair, the user would be able to reopen the same + // gateway on the occupied port only to see an error. if err := gateway.Close(); err != nil { return trace.Wrap(err) }