-
Notifications
You must be signed in to change notification settings - Fork 275
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
Unmarshalling threadUnsafeSet with json.Unmarshal panics #122
Comments
@fabriziosestito - release 2.3.1 has been pushed. Let me know if this satisfies your fix. @fujie-xiyou - thanks for the fix. The other issues that you mentioned in the email should all be tracked as independent Issues/PR's if you feel strongly that other things need to get addressed. |
@deckarep Unfortunately the bug is still here. The only solution I see here is to go back to pointer receivers, otherwise, UnmarshalJSON will not work as it needs to mutate the data. I cannot re-open this issue. |
@fabriziosestito - ok I am reopening and will look into a solution as my time permits. |
I finally got around to looking into this: It's a somewhat nasty bug and the best explanation I have so far: pretty much in all cases when the As it stands, although the test case involved, as posted in the playground link; takes the address of the set object which is a generic interface, the decoder isn't able to resolve that the Changing the test to explicitly use the I don't know how often folks are using the Set with encoding/decoding JSON but I'm curious how others might feel. As it stands there is a very simple workaround. Otherwise, I think the only option is to go back to moving the entirety of all |
Hi, |
I would second the fix, reverting to pointer receivers. I propose the existing behavior could be split into a separate Set implementation, with UnmarshalJSON explicitly disabled (returning a NotImplementedError) with value receivers on the other methods - that way if someone needs that extra performance they can sacrifice JSON unmarshaling to get it, but the bug won't cause panics. |
I third the fix. While eeking out any extra performance is nice, especially on a data structure library, I do not feel the performance tradeoff is worth keeping the bug in place, especially given @dvomartin's example of how it can become a gotcha. |
When using
json.Unmarshal
to deserialize a set of typeUnsafeThreadSet
, a panic is raised.Related to this comment: #121 (comment)
An example can be found here:
https://go.dev/play/p/WgjZEwrHk5U
This was working prior #106, where the pointer receivers were refactored in favor of value receivers.
The text was updated successfully, but these errors were encountered: