-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
morph: support reloading morph endpoints with sighup (#2998)
Closes #1871.
- Loading branch information
Showing
7 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,8 +56,6 @@ type Client struct { | |
|
||
cfg cfg | ||
|
||
endpoints []string | ||
|
||
subs subscriptions | ||
|
||
// channel for internal stop | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package client | ||
|
||
import "slices" | ||
|
||
// Reload allows runtime reconfiguration for WithEndpoints parameter. | ||
func (c *Client) Reload(opts ...Option) { | ||
cfg := new(cfg) | ||
for _, o := range opts { | ||
o(cfg) | ||
} | ||
|
||
c.cfg.endpointsLock.Lock() | ||
|
||
c.cfg.endpoints = cfg.endpoints | ||
|
||
c.cfg.endpointsLock.Unlock() | ||
|
||
conn := c.conn.Load() | ||
if conn == nil { | ||
return | ||
} | ||
|
||
// Close current connection and attempt to reconnect, if there is no endpoint | ||
// in the config to which the client is connected. | ||
// Node service can be interrupted in this case. | ||
if slices.Contains(cfg.endpoints, conn.client.Endpoint()) { | ||
conn.client.Close() | ||
} | ||
} |