deepstreamIO / deepstream.io-client-java

The Java/Android Client for deepstream.io
Other
35 stars 37 forks source link

RecordHandler has many thread safety issues #109

Closed fhriley closed 7 years ago

fhriley commented 7 years ago

The records, lists, and listeners HashMaps of RecordHandler are accessed and modified in non-thread safe ways. There is an attempt in some places to make it thread safe with the following double checked pattern:

Record record = records.get( name );
if( record == null ) {
    synchronized (this) {
        record = records.get( name );
        if (record == null) {
            record = new Record(name, new HashMap(), connection, deepstreamConfig, client);
            records.put(name, record);
...

But that allows HashMap.get to happen simultaneously with HashMap.put. The HashMap javadocs are very clear on this:

If multiple threads access a hash map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally.