fix: avoid singleton mutation in NewFromJsonBytesContext#126
Conversation
a0ba7e6 to
e7b4b42
Compare
afrittoli
left a comment
There was a problem hiding this comment.
Thanks for catching and fixing this. The change looks good.
|
A pin was missing in CI: #127 |
|
@davidlemme-usmobile the PR looks good, but you'll need to rebase it so CI can succeed and then be merged. |
Signed-off-by: David Lemme <david.lemme@usmobile.com>
e7b4b42 to
1f1ad29
Compare
|
My pleasure. Rebased :) |
|
It looks like your fix exposed a unit test that used to pass only because of the bug - the |
Will do working on it shortly |
Signed-off-by: David Lemme <david.lemme@usmobile.com>
58ae009 to
050efc4
Compare
|
added the fix to the tests |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #126 +/- ##
==========================================
+ Coverage 85.12% 85.14% +0.01%
==========================================
Files 149 149
Lines 13097 13098 +1
==========================================
+ Hits 11149 11152 +3
+ Misses 1631 1629 -2
Partials 317 317
🚀 New features to boost your workflow:
|
|
Thank you! |
Fixes #125
NewFromJsonBytesContextunmarshals JSON directly into the singleton pointers stored inCDEventsByUnversionedTypes. Sincejson.Unmarshaldoesn't zeroomitemptyfields absent from the input, values from a previous call leak into subsequent calls for the same event type. This also causes a data race when called concurrently.The fix uses
reflect.Newto create a fresh instance of the concrete type before unmarshalling, so the map entries are only used for type lookup and never mutated.