Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow connections during shutdown #1805

Merged
merged 2 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,37 +612,25 @@ func (m MultiErr) Error() string {
// Close triggers the proxyClient to shut down.
func (c *Client) Close() error {
mnts := c.mnts

var mErr MultiErr

// If FUSE is enabled, unmount it and save a reference to any existing
// socket mounts.
if c.fuseDir != "" {
if err := c.unmountFUSE(); err != nil {
mErr = append(mErr, err)
}
mnts = c.fuseMounts()
}

// First, close all open socket listeners to prevent additional connections.
for _, m := range mnts {
err := m.Close()
if err != nil {
mErr = append(mErr, err)
}
}
if c.fuseDir != "" {
c.waitForFUSEMounts()
}
// Next, close the dialer to prevent any additional refreshes.
// Close the dialer to prevent any additional refreshes.
cErr := c.dialer.Close()
if cErr != nil {
mErr = append(mErr, cErr)
}
if c.conf.WaitOnClose == 0 {
if len(mErr) > 0 {
return mErr
}
return nil
}

// Start a timer for clean shutdown (where all connections are closed).
// While the timer runs, additional connections will be accepted.
timeout := time.After(c.conf.WaitOnClose)
t := time.NewTicker(100 * time.Millisecond)
defer t.Stop()
Expand All @@ -656,9 +644,22 @@ func (c *Client) Close() error {
}
break
}
// Close all open socket listeners. Time to complete shutdown.
for _, m := range mnts {
err := m.Close()
if err != nil {
mErr = append(mErr, err)
}
}
if c.fuseDir != "" {
c.waitForFUSEMounts()
}
// Verify that all connections are closed.
open := atomic.LoadUint64(&c.connCount)
if open > 0 {
mErr = append(mErr, fmt.Errorf("%d connection(s) still open after waiting %v", open, c.conf.WaitOnClose))
if c.conf.WaitOnClose > 0 && open > 0 {
openErr := fmt.Errorf(
"%d connection(s) still open after waiting %v", open, c.conf.WaitOnClose)
mErr = append(mErr, openErr)
}
if len(mErr) > 0 {
return mErr
Expand Down