cloudant / CDTDatastore

Cloudant Sync iOS datastore library.
Apache License 2.0
175 stars 53 forks source link

Synchronise access to _databases dictionary #430

Closed tomblench closed 6 years ago

tomblench commented 6 years ago

What

Synchronise access to _databases dictionary, to handle cases where multiple threads interact with the same CDTDatastoreManager.

Also remove unused method cachedDatabaseNamed.

How

Add @synchronized blocks to stop potential race conditions.

Testing

See xxxTestDatastoreGetThreaded

Issues

Fixes #427 in conjunction with #428

tomblench commented 6 years ago

@ricellis I synchronised close in dd2b6ea because I think there's a race condition where you could get an "orphaned" database.

allOpenDatabases is a read-only view into the map and it doesn't appear to be used except in test code so I'm not worried about that.

tomblench commented 6 years ago

Copyrights and CHANGELOG in 04b3f3f

Note that the log message is intentionally loosely worded - for the same open database you will get different CDTDatastore objects which all point to the same TD_Database. This is OK because the former is just a stateless wrapper around the latter.