forked from TrueCloudLab/frostfs-node
[#749] morph: Fix panic when closing morph client
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
c80b46fad3
commit
a26483fc30
5 changed files with 49 additions and 18 deletions
|
@ -73,6 +73,8 @@ type Client struct {
|
|||
|
||||
// channel for internal stop
|
||||
closeChan chan struct{}
|
||||
closed atomic.Bool
|
||||
wg sync.WaitGroup
|
||||
|
||||
// indicates that Client is not able to
|
||||
// establish connection to any of the
|
||||
|
|
|
@ -75,6 +75,8 @@ func (c *Client) SwitchRPC(ctx context.Context) bool {
|
|||
}
|
||||
|
||||
func (c *Client) closeWaiter(ctx context.Context) {
|
||||
c.wg.Add(1)
|
||||
defer c.wg.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-c.closeChan:
|
||||
|
|
|
@ -16,7 +16,10 @@ func (c *Client) Close() {
|
|||
// closing should be done via the channel
|
||||
// to prevent switching to another RPC node
|
||||
// in the notification loop
|
||||
close(c.closeChan)
|
||||
if c.closed.CompareAndSwap(false, true) {
|
||||
close(c.closeChan)
|
||||
}
|
||||
c.wg.Wait()
|
||||
}
|
||||
|
||||
// ReceiveExecutionNotifications performs subscription for notifications
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue