fix: Proxy closing listener with 0 connections left (#4389)

* fix: Proxy closing listener with 0 connections left

A bug was introduced in `0.15.0` where sessions with max connection counts were closed when the connections left hit 0. This issue was highlighted by a user: https://github.com/hashicorp/boundary/issues/4364. What was happening was when we have zero connections left the proxy code was closing the listener which closed its connections

To fix this:
- `boundary connect  -target-id=xx -host-id=xx` command with no connections left will now wait for all connections to be closed and before exiting the session just like it did in `0.14.3`
- As soon as there are no more connections left, the listener will close to stop accepting new connections
- Fix issue where the websocket connection was throwing closing errors during the session teardown.
This commit is contained in:
Elim Tsiagbey authored and GitHub committed 2024-02-09 18:15:00 -05:00
1 parent a7b9916691
commit 1b1c8b3bf9
3 files changed
+17 -1

No files matched your search

+12
View File
@@ -4,6 +4,18 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
## Next
### Bug Fixes
* cli: Update proxy listener to not close when the number of connections left
for the session is zero. The listener will refuse new connections when the
number of connections left is zero but existing connections will be active.
This fixes a CLI client issue where sessions with max connection count
configured were closed when the number of connections left hit 0.
([Issue](https://github.com/hashicorp/boundary/issues/4364),
([PR](https://github.com/hashicorp/boundary/pull/4389)))
* Fix issue where the websocket connection was throwing closing errors during
the session teardown.
([PR](https://github.com/hashicorp/boundary/pull/4389))
## 0.15.0 (2024/01/30)
+4 -1
View File
@@ -190,7 +190,6 @@ func (p *ClientProxy) Start() (retErr error) {
listenerCloseFunc := func() {
p.listenerCloseOnce.Do(func() {
// Forces the for loop to exit instead of spinning on errors
p.cancel()
p.connectionsLeft.Store(0)
if err := p.listener.Load().(net.Listener).Close(); err != nil && err != net.ErrClosed {
retErr = errors.Join(retErr, fmt.Errorf("error closing proxy listener: %w", err))
@@ -228,6 +227,7 @@ func (p *ClientProxy) Start() (retErr error) {
// connection that comes our way, so cancel the proxy
fin <- fmt.Errorf("error from accept: %w", err)
listenerCloseFunc()
p.cancel()
return
}
}
@@ -241,6 +241,7 @@ func (p *ClientProxy) Start() (retErr error) {
// No reason to think we can successfully handle the next
// connection that comes our way, so cancel the proxy
listenerCloseFunc()
p.cancel()
return
}
if err := p.runTcpProxyV1(wsConn, listeningConn); err != nil {
@@ -248,6 +249,7 @@ func (p *ClientProxy) Start() (retErr error) {
// No reason to think we can successfully handle the next
// connection that comes our way, so cancel the proxy
listenerCloseFunc()
p.cancel()
return
}
}()
@@ -290,6 +292,7 @@ func (p *ClientProxy) Start() (retErr error) {
}()
p.connWg.Wait()
defer p.cancel()
{
// the go funcs are done, so we can safely close the chan and range over any errors
+1
View File
@@ -66,6 +66,7 @@ func (p *ClientProxy) sendSessionTeardown(ctx context.Context) error {
if err := wspb.Write(ctx, wsConn, &handshake); err != nil {
return fmt.Errorf("error sending teardown handshake to worker: %w", err)
}
wsConn.Close(websocket.StatusNormalClosure, "session teardown finished")
return nil
}