Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What do these changes do?
The changes removes the usage of an instance base encoder and generates a new one for each request under the
ChannelAPIClient
Why are these changes necessary?
While its not documented very well, JSONEncoder/Decoder are a stateful objects, which makes them non-thread safe.
We are using version
17.10.0
and facing exceptions around that code, which made me think its a thread issue.In anyway spinning a new encoder/decoder is the recommended way and very cheap in resources.
How did you verify these changes?
Testing for thread safety issues is a hard task, as such I could not create a test to reproduce it.
Here is a thread supporting my theory - https://forums.swift.org/t/is-it-ok-to-create-jsondecoder-only-once-in-withthrowingtaskgroup/57260
Verification Screenshots:
Anything else a reviewer should know?
Here is the stack trace at the app level crash