Socket concurrency protection #67
                
     Closed
            
            
          
  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.
  
    
  
    
If a callback handler for an event such as socket.onOpen calls a method that mutates the callback list, Java will throw a ConcurrentModificationException. The proposed fix makes copies of the lists before invocation, which is a simple change and lock-free.
I'm not sure actually if line 483 is necessary as I think filter already creates a new list. Kotlin appears to differ from C# LINQ in that way, but I don't know if it's guaranteed to be a new list.
Apologies for not including a unit test to expose this but I ran out of time. One of the unit tests in the code base is currently failing for me anyway and also I can't get the project to work reliably in Android Studio. Neither of these points are relevant to the PR, but I thought I would comment in passing.