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

Crash in WebSocket.processInputStream() #367

Closed
kilyukhin opened this issue Aug 9, 2017 · 4 comments
Closed

Crash in WebSocket.processInputStream() #367

kilyukhin opened this issue Aug 9, 2017 · 4 comments

Comments

@kilyukhin
Copy link

Hi,

The problem reported in issue #363 happens in my released app. Looks like there is a concurrency issue inside the library code.

WebSocket.processInputStream is called from WebSocket.stream delegate in a background thread. While the function is being executed, a client code may call WebSocket.disconnect in main queue. So it could happen that between WebSocket.processInputStream start and let length = inputStream!.read(buffer, maxLength: BUFFER_MAX) line inputStream becomes nil and inputStream! unwrapping crashes.
Client code has no access to WebSocket.stream thread and hence has no way to avoid this issue from happening.

Does it make sense to dispatch WebSocket.stream body execution to main queue?

@rastersize
Copy link
Contributor

I’m seeing this issue as well and came to the same conclusion as @kilyukhin. There also seems to be a similar race condition for cleanupStream() where the stream.close() call results in a crash due to CFHash(_:) being given NULL.

@daltoniam
Copy link
Owner

2.1.1 has been released with a fix for this!

@rastersize
Copy link
Contributor

Thank you @daltoniam!

@superlin
Copy link

Still happend in my app with iOS 11.0.3

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

No branches or pull requests

4 participants