fix: panic in broadcast when logout (#4475)

This commit is contained in:
richΛrd 2023-12-19 11:42:50 -04:00 committed by GitHub
parent a5f6a6c2f6
commit e5ce11f067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -1030,7 +1030,9 @@ func (w *Waku) broadcast() {
var fn publishFn
if w.settings.SkipPublishToTopic {
// For now only used in testing to simulate going offline
fn = func(env *protocol.Envelope, logger *zap.Logger) error { return errors.New("test send failure") }
fn = func(env *protocol.Envelope, logger *zap.Logger) error {
return errors.New("test send failure")
}
} else if w.settings.LightClient {
fn = func(env *protocol.Envelope, logger *zap.Logger) error {
logger.Info("publishing message via lightpush")
@ -1045,6 +1047,7 @@ func (w *Waku) broadcast() {
}
}
w.wg.Add(1)
go w.publishEnvelope(envelope, fn, logger)
case <-w.ctx.Done():
return
@ -1055,6 +1058,8 @@ func (w *Waku) broadcast() {
type publishFn = func(envelope *protocol.Envelope, logger *zap.Logger) error
func (w *Waku) publishEnvelope(envelope *protocol.Envelope, publishFn publishFn, logger *zap.Logger) {
defer w.wg.Done()
var event common.EventType
if err := publishFn(envelope, logger); err != nil {
logger.Error("could not send message", zap.Error(err))