Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Potential writeQueue race with sharedWorkQueue #594

Closed
yxztj opened this issue Nov 2, 2018 · 3 comments
Closed

Potential writeQueue race with sharedWorkQueue #594

yxztj opened this issue Nov 2, 2018 · 3 comments

Comments

@yxztj
Copy link

yxztj commented Nov 2, 2018

Per my understanding(please correct me if I'm wrong), outputStream could be accessed on:

  1. Any thread that is trying to call cleanupStream() to release it, which could be in disconnectStream and deinit.
  2. writeQueue: for writing data

So if we are releasing outputStream(could be on any thread) and happens to be writing outStream(on writeQueue) at the same time, then there would be a race condition?

We are seeing intermittent crashes(Starscream 3.0.5) as mentioned in #588, looks like memory corruption by threading issue.

@fassko
Copy link
Collaborator

fassko commented Nov 5, 2018

Hi @yxztj can you show some of the issues you're having? Thanks!

@yxztj
Copy link
Author

yxztj commented Nov 12, 2018

Actually there are 2 different issues:

  1. The writeQueue(OperationQueue) is accessing outputStream on an arbitrary thread while outputStream is being released on another thread, as mentioned in issue description.

screen shot 2018-11-02 at 10 51 33 am

  1. The system is trying to call stream delegate methods on FoundationStream object on FoundationStream.sharedWorkQueue, while we are releasing WebSocket and FoundationStream objects on any thread(probably due to reconnect)

screen shot 2018-11-12 at 12 01 21 pm

@fassko Possible fix could be a combination of 2 steps:

  1. Set writeQueue.underlyingQueue = FoundationStream.sharedWorkQueue, to resolve issue 1
  2. Always release FoundationStream object on FoundationStream.sharedWorkQueue

@fassko
Copy link
Collaborator

fassko commented Nov 12, 2018

@yxztj Maybe you can help out with a PR? Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants