diff --git a/midgen.go b/midgen.go index 9d3acfc..291e297 100644 --- a/midgen.go +++ b/midgen.go @@ -9,6 +9,7 @@ import ( // msgIDGenerator handles computing IDs for msgs // It allows setting custom generators(MsgIdFunction) per topic type msgIDGenerator struct { + sync.Mutex Default MsgIdFunction topicGensLk sync.RWMutex @@ -31,6 +32,8 @@ func (m *msgIDGenerator) Set(topic string, gen MsgIdFunction) { // ID computes ID for the msg or short-circuits with the cached value. func (m *msgIDGenerator) ID(msg *Message) string { + m.Lock() + defer m.Unlock() if msg.ID != "" { return msg.ID } diff --git a/topic.go b/topic.go index c438ebc..3a65052 100644 --- a/topic.go +++ b/topic.go @@ -349,7 +349,9 @@ func (t *Topic) validate(ctx context.Context, data []byte, opts ...PubOpt) (*Mes } msg := &Message{m, "", t.p.host.ID(), pub.validatorData, pub.local} - t.p.rt.Preprocess(t.p.host.ID(), []*Message{msg}) + t.p.eval <- func() { + t.p.rt.Preprocess(t.p.host.ID(), []*Message{msg}) + } err := t.p.val.ValidateLocal(msg) if err != nil { return nil, err