Skip to content

Commit

Permalink
Add support for concurrent RestartSession
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikPelli committed Nov 16, 2024
1 parent fb1cfd7 commit bcc27da
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,20 @@ func (c *Client) RestartSession(ctx context.Context, index int) (oldIPs []net.IP

c.sessionMtx.Lock()
s := c.sessions[index]
if s != nil && s.isReady.Load() {
s.isReady.Store(false)
var swapped bool
if s != nil {
swapped = s.isReady.CompareAndSwap(true, false)
}
c.sessionMtx.Unlock()

if s == nil {
return nil, errors.New("session is not started")
}

if !swapped {
return nil, errors.New("session is already dialing")
}

oldIPs = append(s.assignedIANAs, s.assignedV4Addr)
if err := s.Close(); err != nil {
c.cfg.Logger.Error().Err(err).Int("index", index).Msg("Unable to close session in RestartSession")
Expand Down Expand Up @@ -183,6 +188,7 @@ func (c *Client) Close() error {
}

func (c *Client) dialSessionLoop(ctx context.Context, index int) error {
ctx = context.WithoutCancel(ctx)
duration := c.cfg.Timeout * 3 / 2
t := time.NewTimer(duration)
for {
Expand Down

0 comments on commit bcc27da

Please sign in to comment.