on-internet
← Community

How to solve golang fatal error: concurrent map write

Stack Overflow ·

I am using google pubsub to publish a lot of records which is happening concurrently, but after few dozens of publishes, I get an error : concurrent map write. I have read that I am suppose to use sync.Map{} or sync.Mutex, but I haven't found an example that helped me understand how to use it in my specific situation. Here is a code snippet that causes me problems: md := metadata.Collect(ctx) records, err := s.emailRepository.SetCurrentVersionWithEnsure(ctx, md.GetTransactionId(), valid) if err != nil { return err } for _, value := range records { go s.pub.PublishAction(md, value) } return nil

Comments

Sign in or sign up to comment and upvote.

No comments yet.