Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concurrent map iteration and map write #858

Open
maolinHu opened this issue Oct 8, 2022 · 8 comments
Open

concurrent map iteration and map write #858

maolinHu opened this issue Oct 8, 2022 · 8 comments

Comments

@maolinHu
Copy link

maolinHu commented Oct 8, 2022

Expected behavior

企业微信截图_16652163562552

Actual behavior

Tell us what happens instead

Steps to reproduce

How can we reproduce the issue

System configuration

Pulsar version: 0.8.1

@labuladong
Copy link
Contributor

Can you describe the steps to reproduce this bug?

@zzzming
Copy link
Contributor

zzzming commented Oct 12, 2022

There is a new feature in Go 1.8 to detect concurrent edit and access to a map. It's described at https://tip.golang.org/doc/go1.8#mapiter
The problem was reported (or panicked) by go map.
This should have been reported by a race detector.
I will do a PR to fix it, probably use mutex to protect the map access.

@maolinHu
Copy link
Author

properties := make(map[string]string)
for _, data := range Arr {
msg := &pulsar.ProducerMessage{
Payload: data,
Properties: properties,
}
p.sendAsync(ctx, msg, fn)
}

I guess it is caused by multiplexing map(pulsar.ProducerMessage.Properties) when send asyn, This is an occasional bug.

@zzzming
Copy link
Contributor

zzzming commented Oct 16, 2022

In Go, a map is a reference type. Properties is a map. A producer application can still update the map while it's passed to the go client. This might be where the problem is. The original stack trace is from internalSend that is a Send(). I guess the problem should exist in both Send and SendAsync. The producer application should not concurrently update the properties.

@thomas-bousquet
Copy link

thomas-bousquet commented Jan 13, 2025

Has this issue been fixed? I'm currently experiencing the problem with the version v0.14.0. I'm able to reproduce it with a end-to-end test and the issue is consistent.

Actual behavior

fatal error: concurrent map iteration and map write

Steps to reproduce

  • Create a list of messages (I've tried with 500)
  • Iterate over the list and each time use the producer to SendAsync() to send the individual message.
  • Each message has some properties, like an internal id. I believe the properties list (map[string]string) is causing this issue, as pointed out above.

The fatal error usually occurs after just 40/50 iterations.

@nodece
Copy link
Member

nodece commented Jan 15, 2025

Have you changed the Properties during sending? Do you share the properties for each message?

@thomas-bousquet
Copy link

I had the map used as the source actually shared, when creating the messages individually. Thank you for your help, much appreciated.

@nodece
Copy link
Member

nodece commented Jan 16, 2025

When the map is shared, you will trigger this bug. Please avoid this usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants