Bug:1702
OSX |
Bug 1702: Summary: LAME and FFmpeg loading woes in macOS. Details | Edit |
Summary Points
Our code does 'clever' things with DYLD_LIBRARY_PATH and execv. So (apparently) does Apple's Gatekeeper and dl-loader. Between the two we may have a race condition that leads to these libraries not being found, and possibly the wrong version of a wxWidgets library being found - and a crash in that case.
The Bug Cluster
{{#bugzilla: |id=1702,290,543,1567 |disablecache=1 |columns=id,priority,status,summary,id }}
History (Brief)
- (version 1.3.14) We packaged the executable with a shell script to change environment before invoking Audacity, just so that certain libraries -- which are not loaded until AFTER startup -- would be located correctly by the dynamic loader. (Bug 290)
- (version 2.0.6) To mitigate a very minor downside of the script, not the binary, being the click target in the bundle (bug 543), we got rid of the script, but make Audacity do an execve shortly after starting, a measure which now seems very suspect.
- (version 2.1.3) Possibly as a consequence of that, we got the intermittent bug 1567, only on the newest version of macOS (Sierra), which held up 2.1.3. To fix it sometimes, we compounded the strangeness of the execve with a fork and crash too, and some other work to cleanup .DS_STORE files. We don't fix bug 1567 to our complete satisfaction, but ship 2.1.3 as good enough.
- (version 2.2.0) We observe other weird behavior on Sierra: small changes in size of the executable cause wxWidgets libraries to load from the wrong place at startup; double-click on .aup brings up empty project window.
- Peter 03Aug17: the latter was bug #1703 which was fixed and now marked resolved quickfixed.
History (Detail)
- Before version 1.3.14! Bug 290 reported by David Favor: "(Mac) LAME: Audacity looks for LAME in a restricted folder that Mac no longer supports" https://bugzilla.audacityteam.org/show_bug.cgi?id=290
- Fix made by Leland, introducing file Audacity.sh that changes environment, at https://github.com/audacity/audacity/commit/07661c186f7e8e6d978fa35485d65364b96dfb3a (with explanation starting at https://bugzilla.audacityteam.org/show_bug.cgi?id=290#c9 and more at comment 15 and commit mentioned at comment 21; some Windows problems mentioned too, but apparently fixed then and no longer a problem)
- A modification of that commit at https://github.com/audacity/audacity/commit/c576fc489395a3a4a4e5728e4b534065f82921d2 (introduces shell variable AUDACITY_EXECUTABLE)
- Fix made by Leland, introducing file Audacity.sh that changes environment, at https://github.com/audacity/audacity/commit/07661c186f7e8e6d978fa35485d65364b96dfb3a (with explanation starting at https://bugzilla.audacityteam.org/show_bug.cgi?id=290#c9 and more at comment 15 and commit mentioned at comment 21; some Windows problems mentioned too, but apparently fixed then and no longer a problem)
- Before version 2.0.6: P4 Bug 543 reported by Gale ""Kind" information not sufficiently visible." at https://bugzilla.audacityteam.org/show_bug.cgi?id=543
- A fix just for 543 at https://github.com/audacity/audacity/commit/36361a6b86dac4b0f2b16b7017007b4cc7717c7a removed the Audacity.sh file, introduced the suspicious exeve in main()
- Before version 2.1.3, the notorious bug 1567 "Mac Sierra: LAME, FFmpeg and some plugins disappear. (intermittent)" reported by Gale https://bugzilla.audacityteam.org/show_bug.cgi?id=1567
- Gale observes that force-quitting Audacity from the tool dock can clear the problem, and Paul got the idea to do the equivalient automatically by raising a signal.
- Partial fix to 1567, including the strange fork-and-crash, but keeping the execve, at: https://github.com/audacity/audacity/commit/a05d039055909d7d1dc2d4f31e1fe0659a3207dd
- Other partial fixes to 1567, including certain cleanups of .DS_STORE files: https://github.com/audacity/audacity/commit/dd836f484101cec592ca9255b09384a03279820c https://github.com/audacity/audacity/commit/3ebf9fca209cdacb04d71e09300c2b46d392a27e https://github.com/audacity/audacity/commit/6b65375ee5b3990ec6764dbd71c02b7d9931b660 https://github.com/audacity/audacity/commit/856dfef30f73860821793b5b227714e393872362 https://github.com/audacity/audacity/commit/5b10c386e96b0126e2f3911e83174ab861fad6c0 https://github.com/audacity/audacity/commit/95861bf7f2354b1ee8462573200036ee9e8b8b5a
- Shortly before version 2.1.3: Another commit mentioned in the first bug, Bug 290, by James, at https://github.com/audacity/audacity/commit/0efe931df26da43198b03972ed50b4c3c88b2662
- Maybe relevant too, shortly thereafter, https://github.com/audacity/audacity/commit/2fef7f34b82e1a14af4c4b27f486ce9d13fe3086
- Late July 2017, during 2.2.0 development: a strange problem observed, that some alpha versions of Audacity loaded wxWidgets libraries from the wong, system, paths instead of from the bundle.
- It happened reliably in certain versions, but the problem bisected to a seemingly irrelevant change in the size of one large, static, const array of chars defining theme information. It was also observed that merely redeclaring the arrays a non-const made the problem remit.
- 26 July: Steve also reports that some on the Forum observe that double-clicks on .aup files, while Audacity is not yet running, open the program with an empty window. Not so when the program is previously open. Paul suspects a connection with the execve too.
- Peter 03Aug17: This was logged on Bugzilla as bug #1703 which was subsequently fixed and now marked resolved quickfixed.
Old Proposal (Paul)
My suggestions for the present:
1 Do away with the strange fork, crash, and execve, which I suspect are the unusual things in our program that cause various griefs on macOs Sierra.
2 The loading of LAME and FFmpeg libraries happen AFTER startup, not during. So we should be able to change the environment variables that influence that while Audacity runs, not necessarily before. So there was no need for either the execve or the shell script that existed before that.
- Paul: Experiment shows this doesn't work. The environment variable really must be set before the Audacity process is spawned.
3 Perhaps do away with .DS_STORE cleanup if it isn't needed either. Re-verify bugs 290, 543, and 1567 if we can. (But they may be reports on obsolete OS versions, or intermittent, so verification is difficult.)
Now I think number 2 seems obvious, but in comment 15 of bug 290 Leland mentioned "runtime updates" of environment variables as being available on Windows -- as if they aren't on macOS ?? Or if they are, dyld ignores them?
- Paul: I think he meant to say, updates just to this variable are ignored by dyld.
Comments (James)
- +1 to 1 and 2.
- We could/should also add something so we log env variables that are involved in loading so we know if them changing is causing a problem.
Resolution (Paul)
After I wrote the above, I decided differently.
I reverted to the original fix for bug 290, as of https://github.com/audacity/audacity/commit/dba49dd485d718a7ce5e42cf1cf4a7990d2e6a59
The fix removes the execve funny business, and instead makes a tiny script, Audacity.sh, as part of the bundle, which changes the environment and invokes Audacity. I know GIMP at least is one other program doing the same trick, as you can see by exploring its package.
This reopens Bug 543, but I decided to resolve that as won't fix. (It might be fixed if the shell program is rewritten as a C program. Not worth the effort.) I now think the fix for 543 was the cause of all the other grief.
As for Bug 1567, it may be impossible to test now. It happened only to a few users, according to rumors at the forum, and only to Gale among team members. Even he saw the symptom only with dozens of rapid starts and exits of Audacity. I am inclined, though, to take the fix of 1703 as circumstantial evidence, that removing the funny business cures a variety of unintended side effects at process startup. So let's mark this bug not reproducible and simpy wait for reports of recurrence.
This said, I am still puzzled by DYLD_LIBRARY_PATH. Apparently SIP (System Integrity Protection) since El Capitan includes very special treatment of this environment variable. Experiments with interactive sh show that the shell quietly refuses to export the changed variable to a sub-shell or other process. And yet experiment also showed that this was not so when Audacity.sh was invoked as part of the bundle.
Did the original Bug290 happen (as the report says, only on some systems) because DYLD_LIBRARY_PATH was somehow set by default (by malicious programs maybe)? Is this just not possible after SIP? Does that make 290 a non-issue on those systems? And yet we are still supporting an earlier minimum macOs version than El Capitan.
- MoonphaseBug
- Bug OSX
- P1
- Bug