Bug 37794 - setenv crashes when used
Summary: setenv crashes when used
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: XI 9.8 (tvOS / C7)
Hardware: PC Mac OS
: High normal
Target Milestone: Future Cycle (TBD)
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2016-01-19 14:25 UTC by Alan McGovern
Modified: 2016-08-01 14:22 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alan McGovern 2016-01-19 14:25:18 UTC
My app sometimes crashes with this on startup: https://gist.github.com/alanmcgovern/4c4c3f835ebab4b42cc1

Rolf found out it was not a threadsafe function and will crash your app if used:
Comment 1 Alan McGovern 2016-01-19 14:26:04 UTC
The crashing thread is:
Thread 1 Crashed:: Dispatch queue: com.apple.libdispatch-manager
0   libsystem_c.dylib             	0x00007fff90ec3a9b __findenv + 90
1   libsystem_c.dylib             	0x00007fff90ec3b1f getenv + 29
2   libdispatch.dylib             	0x00007fff92202321 _dispatch_mgr_init + 179
3   libdispatch.dylib             	0x00007fff9220224a _dispatch_mgr_thread + 16
4   libdispatch.dylib             	0x00007fff92200bef _dispatch_root_queue_drain + 463
5   libdispatch.dylib             	0x00007fff922021a3 _dispatch_worker_thread + 101
6   libsystem_pthread.dylib       	0x00007fff909ed05a _pthread_body + 131
7   libsystem_pthread.dylib       	0x00007fff909ecfd7 _pthread_start + 176
8   libsystem_pthread.dylib       	0x00007fff909ea3ed thread_start + 13
Comment 2 Rolf Bjarne Kvinge [MSFT] 2016-01-19 14:28:32 UTC
This seems to be because setenv isn't threadsafe (!!!).

So we need to remove our setenv usage (alternatively only use it while we can sure the only thread is the main thread, but I don't think we can make that guarantee easily).
Comment 3 Rolf Bjarne Kvinge [MSFT] 2016-06-09 16:52:03 UTC
I'm starting to see this more frequently now, I have 4 crash reports from the two last days.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2016-08-01 14:22:45 UTC

master: https://github.com/xamarin/xamarin-macios/commit/eed9b5d8d015b0beacb6c6929a31f1d198d7d811