Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

mts_setValuesForKeysWithDictionary not thread-safe #17

Closed
jpmhouston opened this issue Nov 26, 2014 · 6 comments
Closed

mts_setValuesForKeysWithDictionary not thread-safe #17

jpmhouston opened this issue Nov 26, 2014 · 6 comments
Assignees

Comments

@jpmhouston
Copy link

I've been seeing occasional crashes "error for object 0x7fbf1b42bbb0: pointer being freed was not allocated" in places like the dictionary[typeAttribute] = isClassType; line of mts_isClassTypeTypeAttribute.

Searching the web for NSMutableDictionary "pointer being freed was not allocated" found http://stackoverflow.com/a/16976032 warning about "mutating the dictionary's contents on different threads at the same time", and I see that our app is indeed calling mts_setValuesForKeysWithDictionary from within several occurrences of a dispatch_async(dispatch_get_global_queue(..) block.

Can I get any tips for making mts_setValuesForKeysWithDictionary thread safe? I see several category methods in NSObject+Motis.m that use a static NSMutableDictionary to cache results for the same type, optimizations I can either disable or make thread-safe. Is there anything more subtle I also need to look at?

@vilanovi
Copy link
Contributor

vilanovi commented Dec 2, 2014

Hello @jpmhouston,

Thanks for posting your issue.

We are currently caching all this data in these dictionaries to speed up Motis, as all the introspection calls are very slow (and we try to cache as much as possible the result of this introspection).

Therefore, I would encourage you to NOT disable all the caching. However, what we can do is make Motis thread-safe, and protect those parts of the code that might be not thread safe, as the mutable dictionary manipulation.

I'll be working on this as soon as I can (at some moment this week). However if meanwhile you want to try to fix it, you are more than welcome :).

I'll keep you updated.

@R1ckye
Copy link

R1ckye commented Dec 19, 2014

Hi,

I've also been seeing this issue for a while now, any news on a fix?

Thanks

@vilanovi
Copy link
Contributor

vilanovi commented Jan 8, 2015

Hello @R1ckye and @jpmhouston,

Sorry for the delay. Version 1.0.2 Thread Safe of Motis is already available in Cocoa Pods.

Please, test int and report any issue you find. I've been testing and I could not reproduce anymore any crash caused by non thread safe calls to dictionaries.

Now, it still pending optimize a bit the synchronization done. I'll schedule it as my next task.

Thanks,

@vilanovi vilanovi closed this as completed Jan 8, 2015
@vilanovi
Copy link
Contributor

Hello @samkaufman and @jpmhouston,

I've seen you have forked Motis and modified it to make it thread safe. For your information, Motis is from 1.0.2 now Thread Safe (and still using the objective-c runtime cache layer).

Feel free to pull changes to your forked repository.

Cheers,

Joan

@vilanovi vilanovi self-assigned this Jan 10, 2015
@samkaufman
Copy link
Contributor

@vilanovi This is fantastic. Thanks, Joan. Very happy to have the introspection result caches back.

@vilanovi
Copy link
Contributor

@samkaufman You are welcome!. And my apologies for the delay of solving this issue. I've been traveling and I could not do it before. ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants