Bug 38708 - NRE in ServicePoint.CheckAvaliableForRecycling
Summary: NRE in ServicePoint.CheckAvaliableForRecycling
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 9.2
Hardware: Other Other
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-02-12 10:05 UTC by Lucian Torje
Modified: 2016-06-27 17:14 UTC (History)
8 users (show)

Tags: BZCU
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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Lucian Torje 2016-02-12 10:05:19 UTC
System.NullReferenceException: Object reference not set to an instance of an object↵  at System.Net.ServicePoint.CheckAvailableForRecycling (System.DateTime& outIdleSince) [0x00000] in <filename unknown>:0 ↵  at System.Net.ServicePoint.IdleTimerCallback (System.Object obj) [0x00000] in <filename unknown>:0 ↵  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <filename unknown>:0

App Store app compiled with Xcode 7.2, mtouch 9.2.1.54 (cycle6-xi: eb4c1ef), /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/4.5
Comment 1 Sebastien Pouliot 2016-02-12 14:10:26 UTC
Do you have a test case that can reproduce this ?
Comment 2 Lucian Torje 2016-02-12 14:30:45 UTC
Unfortunately not, it happens only with the App Store app (arm64) and I did not manage to reproduce it yet.

It affects only 9.0, 9.0.2, 9.1, 9.2, 9.2.1 iOS devices - no issues detected on iOS 7 & 8.
Comment 3 Sebastien Pouliot 2016-03-02 15:11:56 UTC
XI 9.4.x ships only with a managed HTTP stack so the iOS version should have no impact.

Ideally we would need a test case (even if hard to reproduce). Otherwise a complete, symbolicated, crash report might give us more information about the crash (e.g. what the other threads are doing at that time).
Comment 4 Lucian Torje 2016-03-02 15:20:03 UTC
This is the only info I have - the exception is caught inside AppDomain.CurrentDomain.UnhandledException and the app does no log the stack info.

Can you please add more details on why using the managed HTTP stack should not impact iOS.
Comment 5 Sebastien Pouliot 2016-03-02 21:45:45 UTC
> should not impact iOS.

The _version_ of iOS should have no impact because there's no iOS specific call in that code and you're hitting a managed exception.

It might be a related to #32685 (e.g. partially fixed) -> Marek
Comment 6 Monica Tvedt 2016-03-22 09:50:09 UTC
I have the same problem. Crashing when trying to send ie. significant location change updates, resulting in: 

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

From Xamarin Insights I see affected OS as:
iOS 9.2.1	73.3%
iOS 7.1.2	11.9%
iOS 9.2	         5.9%
iOS 8.3	         2.6%
iOS 8.4	         1.5%
(Other)	         4.8%
Comment 7 Bernhard Urban 2016-03-22 21:04:26 UTC
A testcase to reproduce this would be really nice.

@Monica Tvedt: Do you have a bit more information, e.g. XI version, on what devices do you see crashes, ...?
Comment 8 Monica Tvedt 2016-03-23 10:47:53 UTC
This is Xamarin.Forms v1.5.1.6471.
It seems to only affect iOS as posted above. I cannot see what "Other" is. The same goes for affected devices. "Other" is not spesified.

Affected devices:

iPhone 5 (v5,2)	        27.7%
iPhone 4S	        19.9%
iPhone 6	        12.7%
iPhone 5s (v6,2)	12.7%
iPhone 5c (v5,4)	11.4%
(Other)	                15.7%


The methods in which this seems to happen the most (from what I can gather from our logs) is:

1: Subscribe to SignificantLocationUpdate -------------------------

MessagingCenter.Subscribe<LocationInfo>(this, "SignificantLocationUpdate", sender =>
            {
                Debug.WriteLine("From subscribe SignificantLocationUpdate: " + sender.Timestamp);
                Insights.Track("Send LocationChange");
                DependencyService.Get<IConnectionManager>().PutPos(sender);
                MyLocation = new Location
                {
                    Latitude = sender.Latitude,
                    Longitude = sender.Longitude,
                    Radius = sender.Radius
                };
            });

The log then states:

March 21, 2016 7:31amUTC
Crashed                 1s
Send LocationChange     0s

----------------------------------------------

2:  ------------------------------------------

 MessagingCenter.Subscribe<ConnectionMessage>(this, "ErrorEvent", sender =>
            {
                Insights.Track("Tcp error event: " + sender.Message);
               
                App.IsConnecting = true;
                IsConnected = false;
                IsLoggedIn = false;

                Insights.Track("Connect from ErrorEvent subscription");

                Device.BeginInvokeOnMainThread(async () =>
                {
                    var connectRetryWaitSecs = FindConnectRetryTimeSpan();
                    Debug.WriteLine("Error event received, failCount is {0} wait for {1} seconds, then reconnect", ConnectRetyCount, connectRetryWaitSecs.TotalSeconds);
                    await Task.Delay(connectRetryWaitSecs);
                    DependencyService.Get<IConnectionManager>().Connect(AppSettingsResources.Host, AppSettingsResources.Port);
                    ConnectRetyCount++;
                });
});

The log then states:

March 21, 2016 6:41amUTC
Send LocationChange                  0s
Connect from ErrorEvent subscription 0s
Crashed                              0s
Tcp error event: ErrorOccurred       0s

--------------------------------------------------
Comment 9 Monica Tvedt 2016-03-23 10:53:07 UTC
Stacktrace for all crashes then are given as: 

System.NullReferenceExceptionObject reference not set to an instance of an object
at System.Net.ServicePoint.CheckAvailableForRecycling(ref DateTime outIdleSince) 
at System.Net.ServicePoint.IdleTimerCallback(object obj)
at System.Threading.Timer.Scheduler.TimerCB(object o)

------------------------------------------
RAW:
Warning: Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object
  at System.Net.ServicePoint.CheckAvailableForRecycling (System.DateTime& outIdleSince) [0x00000] in <filename unknown>:0 
  at System.Net.ServicePoint.IdleTimerCallback (System.Object obj) [0x00000] in <filename unknown>:0 
  at System.Threading.Timer+Scheduler.TimerCB (System.Object o) [0x00000] in <filename unknown>:0 
-------------------------------------------
Comment 10 Bernhard Urban 2016-03-28 17:57:01 UTC
Thanks Monica.  I could come up with a repro that only crashes only if I undo the fix in #32685 (see https://gist.github.com/lewurm/2ccc6dd3057979d5564d ). With the fix, it ran multiple hours fine on the iPhone device I have here to test.  Can you check which version of Xamarin.iOS you're compiling your app?

@Lucian: In my understanding, your installed version of Xamarin.iOS (cycle6-xi: eb4c1ef) should contain the fix; anyway, can you try to update and see if it still happens with a newer version?
Comment 11 Bernhard Urban 2016-03-28 22:11:55 UTC
Another theory: Could it be that there're still old apps out there, that are reporting to Insights?  Old in the sense of, it was compiled with an older Xamarin.iOS version that doesn't include the fix from #32685
Comment 12 Lucian Torje 2016-03-29 06:45:48 UTC
I've updated to 

xcode 7.2.1
xamarin studio 5.10.3(build26)
xamarin iOS 9.4.2.27
mono 4.2.3

In my case, I know for sure that there were not older build involved.
Comment 13 Manuel de la Peña [MSFT] 2016-06-27 08:55:53 UTC
@Bernhard can you please try and reproduce the above again?
Comment 14 Bernhard Urban 2016-06-27 17:14:41 UTC
Couldn't reproduce it with current version (see comment #10). I close it for now. Please reopen if you can provide a testcase that crashes on current versions.