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:
Zoltán Papp
2025-08-07 23:29:05 +02:00
parent 1c1af3f5be
commit 0fcb272f05
2 changed files with 6 additions and 5 deletions

View File

@@ -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)

View File

@@ -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
}
}