mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-20 23:41:28 +02:00
Fix worker restart
When the signal connection is lost, we do not recreate the gRPC instance but instead cancel the context. As a result, the worker is stopped but not restarted.
This commit is contained in:
@@ -160,7 +160,7 @@ func (c *GrpcClient) Receive(ctx context.Context, msgHandler func(msg *proto.Mes
|
||||
c.notifyConnected()
|
||||
|
||||
// Start worker pool if not already started
|
||||
c.startEncryptionWorker(ctx, msgHandler)
|
||||
c.startEncryptionWorker(msgHandler)
|
||||
|
||||
// start receiving messages from the Signal stream (from other peers through signal)
|
||||
err = c.receive(stream)
|
||||
@@ -427,15 +427,16 @@ func (c *GrpcClient) receive(stream proto.SignalExchange_ConnectStreamClient) er
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GrpcClient) startEncryptionWorker(ctx context.Context, handler func(msg *proto.Message) error) {
|
||||
func (c *GrpcClient) startEncryptionWorker(handler func(msg *proto.Message) error) {
|
||||
if c.decryptionWorker != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.decryptionWorker = NewWorker(c.decryptMessage, handler)
|
||||
c.decryptionWg.Add(1)
|
||||
workerCtx, workerCancel := context.WithCancel(ctx)
|
||||
workerCtx, workerCancel := context.WithCancel(context.Background())
|
||||
c.decryptionWorkerCancel = workerCancel
|
||||
|
||||
c.decryptionWg.Add(1)
|
||||
go func() {
|
||||
defer workerCancel()
|
||||
c.decryptionWorker.Work(workerCtx)
|
||||
|
||||
@@ -48,7 +48,7 @@ func (w *Worker) Work(ctx context.Context) {
|
||||
}
|
||||
|
||||
case <-ctx.Done():
|
||||
log.Debugf("Message worker stopping due to context cancellation")
|
||||
log.Infof("Message worker stopping due to context cancellation")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user