Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: std::__1::system_error mutex lock failed: Invalid argument #892

Closed
zhfeng20108 opened this issue Nov 14, 2017 · 8 comments

Comments

@zhfeng20108
Copy link

2017-11-14 2 34 31

2017-11-14 2 35 20

@gkassabli
Copy link
Contributor

This is likely happening during the system teardown when application is closing, so I don't think crash is relevant.
If you think this is happening in other conditions, please post more detailed explanation how to reproduce the issue.

@yanni-fe
Copy link

yanni-fe commented Jan 8, 2018

@zhfeng20108 Are you still having this problem? Can you reproduce this issue?

@zhfeng20108
Copy link
Author

2018-04-12 10 27 34

This issue happened too much. Is there a way to avoid it?

@zhfeng20108
Copy link
Author

@gkassabli

@ocrickard
Copy link
Contributor

Wait, this is an error in mutex locking? That is almost certainly a heap corruption. It's crashing at this line, but the reason it is crashing is that the mutex has been stomped by some other code.

Historically, TextKit has had lots of hidden thread-safety issues despite being stated as thread safe. CK locks around all access to TextKit, but there are still issues that have cropped up in the recent past. We built the same text locking system in both CK and ASDK, and they both work this way.

Are there any other users of CK that run into the same issue? If so, then it's possible that there's a stomper inside the TextKit wrappers in CK itself (though, I doubt that).

If this is only happening in your app, then it's possible that your app is stomping the memory through an unprotected access.

(disclaimer, I don't work on CK anymore, just an avid observer. I won't be able to help with any actual fixes)

@ocrickard
Copy link
Contributor

Oh god, wait, someone should check that the static mutex in the TextKit impl isn't susceptible to the static destructor fiasco. cc @adamjernst who will be able to check. That would probably manifest in this way if one thread is attempting to tear down while another thread tries to lock, right?

@ocrickard
Copy link
Contributor

Specifically this line: https://github.com/facebook/componentkit/blob/master/ComponentTextKit/TextKit/CKTextKitContext.mm#L33

I'd appreciate @adamjernst or @eczarny checking on me that that line is correct, and won't crash on exit().

@ocrickard
Copy link
Contributor

OK, looks like std::mutex is not trivially destructible in Clang, so we should probably just leak that mutex. Anyway, I believe this crash is happening on exit() as @gkassabli said above, so it probably has no impact on user experience.

ocrickard added a commit to ocrickard/componentkit that referenced this issue Apr 12, 2018
…ructor fiasco

I haven't tested this code, but this is what I would try to resolve facebook#892. Someone should run some smoke tests with something like the above
facebook-github-bot pushed a commit that referenced this issue May 1, 2018
…ructor fiasco

Summary:
OSS CK is crashing on the exit. The probable cause is that it is static mutex is destroyed at the same time when another thread tries to lock it.
This diff leaks the mutex in order to avoid that crash

I haven't tested this code, but this is what I would try to resolve #892. Someone should run some smoke tests with something like the above
Closes #906

Reviewed By: kfirapps

Differential Revision: D7616427

Pulled By: gkassabli

fbshipit-source-id: fe4d9fc1add8228d3bd672f853cca8d54a02bc58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants