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

copy evt.Codes to avoid concurrency issues #725

Closed
wants to merge 1 commit into from

Conversation

devlikepro
Copy link

@devlikepro devlikepro commented Jan 9, 2025

Right now in emitQRs function changes the original event, events.QR.
However, we send it already to other handlers, but we change it here.

In my case, I tried to JSON.Marshal(evt) and sometimes got reflect: slice index out of range concurrency error.

It looks like instead of changing evt.Codes we should copy it first and then change copied slice.

It's minor issue, but it's better not to change the values we already send outside, IMO.

Not sure if coping it before Marshal would help btw, because it'll be anyway concurrent access 🤔

@tulir
Copy link
Owner

tulir commented Jan 31, 2025

It's probably easier to just not use the QR channel if you want to manage QR codes yourself 🤔

@devlikepro
Copy link
Author

@tulir the main idea - if you send event outside it should have "concurrent" access to it, not be changed after you sent it.

You can close PR if you feel, fine for me!
We handled panic in JSON serialization, but I'd say it's good practice to avoid changing objects after sending it to consumers.

if you want to manage QR codes yourself

I don't, I love the way how qr channel does it.
I just wanted to dump all "events" from meow to JSON for troubleshooting/debug purpose.

@tulir
Copy link
Owner

tulir commented Feb 5, 2025

The other problem is that the PR is implemented incorrectly

@tulir tulir closed this in e43fe38 Feb 5, 2025
@devlikepro
Copy link
Author

omg, you're right! It was an empty slice before 😨 Thank you for the fix! 🙇

crazycodezombie pushed a commit to crazycodezombie/whatsmeow that referenced this pull request Feb 8, 2025
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

Successfully merging this pull request may close these issues.

2 participants