davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
506 stars 146 forks source link

Prevent crashes caused by threading issues #252

Closed ejensen closed 7 months ago

ejensen commented 7 months ago

Overview

This PR addresses a few crashes caused by threading issues in array mutation. The symptoms of these crashes are EXC_BREAKPOINT, SIGABRT ABORT, and EXC_BAD_ACCESS KERN_INVALID_ADDRESS exceptions on the spc_sync_array thread. The exceptions have the following details:

CrashLog

Issues being addressed

  1. Instances of the SychronizedArray class were being replaced rather than updated. Replacing the instances of SychronizedArray removes the safety the SychronizedArray type provides. It also results in the spc_sync_array dispatch queue owned by SychronizedArray becoming unowned when the SychronizedArray instance deallocates, causing SIGABRT ABORT and EXC_BAD_ACCESS KERN_INVALID_ADDRESS exceptions when the operations of the queue execute.
    • This issue is addressed by making SychronizedArray instances lets and using the synchronized functions of SychronizedArray to update the underlying array variable
  2. The sendBuffer array was being mutated on multiple threads, causing EXC_BREAKPOINT exceptions
    • This issue is addressed by using SychronizedArray
ejensen commented 7 months ago

@dsrees when you get a chance, can you take a look at these changes?

dsrees commented 7 months ago

@ejensen Thanks! These threading issues are always hard to track down in the wild so I appreciate the contribution

ejensen commented 7 months ago

Thank you @dsrees! Do you think this fix can be included in a 5.3.2 bug fix version release?

dsrees commented 7 months ago

done