Bug 32685 - NRE in ServicePoint.CheckAvaliableForRecycling
Summary: NRE in ServicePoint.CheckAvaliableForRecycling
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
: 32689 34745 35226 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-07-31 18:12 UTC by Tom Philpot
Modified: 2016-03-14 21:46 UTC (History)
13 users (show)

Tags:
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 GitHub or Developer Community 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:
Status:
RESOLVED FIXED

Description Tom Philpot 2015-07-31 18:12:10 UTC
We are seeing the following stack trace in a Xamarin.iOS app in Raygun.

NullReferenceException: Object reference not set to an instance of an object
 System.Net.ServicePoint.CheckAvailableForRecycling(System.DateTime& outIdleSince) in <filename unknown>:0
 System.Net.ServicePoint.IdleTimerCallback(System.Object obj) in <filename unknown>:0
 System.Threading.Timer+Scheduler.TimerCB(System.Object o) in <filename unknown>:0

We are using Xamarin.iOS 8.10.3.2 and have seen the error reported on iOS 8 and 9.

I believe the error has to do with this commit: https://github.com/mono/mono/commit/a769e74c5320f2cfa85efe80f2e1c1d8470c271b

Specifically, https://github.com/mono/mono/blob/a769e74c5320f2cfa85efe80f2e1c1d8470c271b/mcs/class/System/System.Net/ServicePoint.cs#L317 might need a check for groups != null.

Possible repro:
1. Thread 1 calls CheckAvailableForRecycling
2. Thread 2 calls CheckAvailableForRecycling
3. Thread 1 locks (this) and builds groupList
4. Thread 2 locks (this) and builds groupList, while Thread 1 is iterating groupList (lines 304-310)
5. Thread 1 locks (this) on line 312, while Thread 2 is iterating groupList.
6. While holding lock, Thread 1 sets groups to null.
7. Thread 1 exits lock
8. Thread 2 locks (this) on line 312 and groups is null. => NRE
Comment 1 Tom Philpot 2015-07-31 18:43:22 UTC
See https://github.com/mono/mono/pull/1955
Comment 2 Marek Safar 2015-08-01 02:55:31 UTC
Fixed in mono master and Mono 4.2
Comment 3 Marek Safar 2015-08-02 07:26:23 UTC
*** Bug 32689 has been marked as a duplicate of this bug. ***
Comment 4 Marek Safar 2016-01-14 14:50:27 UTC
*** Bug 34745 has been marked as a duplicate of this bug. ***
Comment 5 Marek Safar 2016-01-14 14:50:36 UTC
*** Bug 35226 has been marked as a duplicate of this bug. ***
Comment 6 Marek Safar 2016-01-14 14:51:40 UTC
Only Xamarin.iOS 9.2 or newer versions have the fix included
Comment 7 Lucian Torje 2016-02-11 09:41:24 UTC
Not fixed: Xcode 7.2, mtouch 9.2.1.54 (cycle6-xi: eb4c1ef), /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/4.5