NSJSONSerialization writeJSONObject crashes if stream has error
Open
bug
crash
low priority
- Dominant language
- Swift
- Stars
- 35.5k
- Forks
- 1.8k
- Avg merge
- 5d 5h
- Merged PRs (30d)
- 7
Description
Only really an issue in the "quit" command where the stream could terminate in middle of processing.
We have code to guard this
```objc
if (!_outputStream || _outputStream.streamStatus != NSStreamStatusOpen) {
return NO;
}
```
But there's a race condition because by the time we call
```objc
[NSJSONSerialization writeJSONObject:dict toStream:_outputStream options:0 error:&err];
```
the stream could be closed at anytime. `writeJSONObject` does not seem to be thread safe so it will crash.
Seems like this happens infrequently. Since we terminate the app anyways, it doesn't matter TOO much that it crashes at the end.
Contributor guide
Assessment
This issue has not been assessed yet.