Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

jetstream: fix data race filtering events by did

Signed-off-by: Thomas Karpiniec <tkarpiniec@icloud.com>

authored by

Thomas Karpiniec and committed by
Tangled
ec98937d f5a9a663

+15 -4
+15 -4
jetstream/jetstream.go
··· 72 72 // existing instances of the closure when j.WantedDids is mutated 73 73 return func(ctx context.Context, evt *models.Event) error { 74 74 75 + j.mu.RLock() 75 76 // empty filter => all dids allowed 76 - if len(j.wantedDids) == 0 { 77 - return processFunc(ctx, evt) 77 + matches := len(j.wantedDids) == 0 78 + if !matches { 79 + if _, ok := j.wantedDids[evt.Did]; ok { 80 + matches = true 81 + } 78 82 } 83 + j.mu.RUnlock() 79 84 80 - if _, ok := j.wantedDids[evt.Did]; ok { 85 + if matches { 81 86 return processFunc(ctx, evt) 82 87 } else { 83 88 return nil ··· 127 122 128 123 go func() { 129 124 if j.waitForDid { 130 - for len(j.wantedDids) == 0 { 125 + for { 126 + j.mu.RLock() 127 + hasDid := len(j.wantedDids) != 0 128 + j.mu.RUnlock() 129 + if hasDid { 130 + break 131 + } 131 132 time.Sleep(time.Second) 132 133 } 133 134 }