3 ms·
I was thinking about Python when reading this, the real culprit is not objc but the third-party modules. If I understand correctly, this problem is caused when
by captainmuon 9y ago
I was thinking about Python when reading this, the real culprit is not objc but the third-party modules.
If I understand correctly, this problem is caused when you call initialize in another thread, and while that is running, you fork.
It affects these app servers because this is triggered at "require" (or "import") time. This is madness, no module should run code just when you import it. OK, I have been guilty of that, too. But if absolutely neccessary, keep it to a minimum. It breaks all kind of things when module imports are not side-effect-free.
Launching a thread and (indirectly) taking a mutex is definitely not something you should do on module import!
- dchest 9y agoAs far as I understood, the module isn't launching threads at import time. On the contrary, the problem is that since pg is linked against macOS's Kerberos and LDAP frameworks, as soon as the Objective-C runtime realizes that NSPlaceholderDictionary initialize method was called after fork(), it crashes: One of the rules that Apple defined is that you may not call Foundation class initializers after forking.
- captainmuon 9y agoIn that case, the new behavior doesn't make sense. You could call `fork` as the very first thing in a program, and then do all the stuff in the subprocess, and I wouldn't expect it to make a big difference. Maybe there is an internal `mark_exec_as_called()` function that you could exploit, if you are forking without exec...
- eridius 9y agoWell, something must be spawning a thread first. From the Obj-C source¹, the comment on performForkChildInitialize() (the point where this crash happens) says > Exception: processes that are single-threaded when fork() is called have no restrictions on +initialize in the child. Examples: sshd and httpd. ¹ https://opensource.apple.com/source/objc4/objc4-723/runtime/objc-initialize.mm.auto.html https://opensource.apple.com/source/objc4/objc4-723/runtime/...