Bug 52379 - Application UI freeze when NSUrlProtocol and UIWebView are used.
Summary: Application UI freeze when NSUrlProtocol and UIWebView are used.
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime (show other bugs)
Version: XI 10.3 (iOS 10.2)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-02-08 11:51 UTC by Alex
Modified: 2018-02-12 15:58 UTC (History)
5 users (show)

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


Attachments
Project to reproduce the bug (17.10 KB, application/zip)
2017-02-08 11:51 UTC, Alex
Details
Screenshot of call stack (99.72 KB, image/png)
2017-12-15 12:30 UTC, Alex
Details
Swift sample application (36.76 KB, application/zip)
2018-02-08 16:31 UTC, Manuel de la Peña [MSFT]
Details
TestProtocolWithManyWebViews.zip (65.75 KB, application/zip)
2018-02-09 12:07 UTC, Alex
Details


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 for Bug 52379 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Alex 2017-02-08 11:51:28 UTC
Created attachment 19756 [details]
Project to reproduce the bug

Application becomes freeze and unresponsive when NSUrlProtocol and UIWebView are used.

I implemented subclass of NSUrlProtocl and registered it to respone on image loading. In some moment application stops to respond to user actions. If if pause the program execution then I see that UIThread is blocked with following stack:

    Foundation.NSObject.xamarin_release_managed_ref() in 
    Foundation.NSObject.ReleaseManagedRef() in /Users/builder/data/lanes/3969/7beaef43/source/xamarinmacios/src/Foundation/NSObject2.cs:208
    Foundation.NSObject.NSObject_Disposer.Drain( ctx) in /Users/builder/data/lanes/3969/7beaef43/source/xamarinmacios/src/Foundation/NSObject2.cs:784


I've attached test project to reproduce the bug. You should click the "Refresh screen" button until application will have been freezed.
Also I've made a native project and there bug didn't appear.
Comment 1 Manuel de la Peña [MSFT] 2017-02-10 10:36:52 UTC
I have tested the application with the following env:

=== Xamarin Studio Community ===

Version 6.1.5 (build 0)
Installation UUID: 01060673-5bee-4cf4-a4c2-5e36a18d39a2
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/e8f4c7c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000289

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.Mac ===

Version: 2.10.0.120 (Xamarin Studio Community)

=== Xamarin.Android ===

Version: 7.0.2.42 (Xamarin Studio Community)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 25.1.6
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: 10.3.1.8 (Xamarin Studio Community)
Hash: 7beaef4
Branch: cycle8-xi
Build date: 2016-12-20 02:58:14-0500

=== Xamarin Inspector ===

Version: 1.0.0.0
Hash: 1f3067d
Branch: master
Build date: 11/15/2016 10:13:59 PM

=== Build Information ===

Release ID: 601050000
Git revision: 7494718e127af9eaec45a3bd6282d3da927488bd
Build date: 2017-01-17 10:31:01-05
Xamarin addins: c92d0626d347aaa02839689eaac2961d24c9f446
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.12.3
Darwin MacBook-Pro.local 16.4.0 Darwin Kernel Version 16.4.0
    Thu Dec 22 22:53:21 PST 2016
    root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Addin Maker 1.3.2
StyleCop Support 1.0.1.9
Xamarin Inspector 1.0.0.0
Manifest.addin 0.0.0.0
Comment 2 Vladimir Abakumov 2017-12-13 07:15:40 UTC
I have got this problem too. The Xamarin.iOS app have hung in some undefined moments. All threads even main were staying on Foundation.NSObject.xamarin_release_managed_ref()
Comment 3 Vladimir Abakumov 2017-12-13 07:19:07 UTC
Alex, did you find the workaround?
Comment 4 Alex 2017-12-15 11:13:39 UTC
Hello, Vladimir!
I've created a native binding to handle this issue. Please, check here
https://github.com/aserdobintsev/NativeProtocolBinding
Comment 5 Manuel de la Peña [MSFT] 2017-12-15 12:14:16 UTC
Hello,

I tested the test application with current master and I did not see any issues anymore in the simulator or in a iOS 11 device. The env used to test is the following:

=== Visual Studio Community 2017 for Mac ===

Version Preview - Internal Dogfood (7.3.2 build 10)
Installation UUID: 8d12e55e-3489-463f-ac52-8cb4573c5a81
Runtime:
	Mono 5.8.0.39 (2017-10/99db2351979) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 508000039

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.0
	1.1.2
	1.0.5
	1.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Versions:
	2.0.0
	1.0.4
	1.0.0-preview2-003121
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.8.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 8.1.0.24 (Visual Studio Community)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.iOS ===

Version: 11.7.0.252 (Visual Studio Community)
Hash: 1e777cdf
Branch: master
Build date: 2017-12-14 14:20:21+0100

=== Xamarin.Mac ===

Version: 4.1.0.540 (Visual Studio Community)

=== Build Information ===

Release ID: 703020010
Git revision: d203af94011a0bfba0685a67e73281a53c25e393
Build date: 2017-12-07 11:00:27-05
Xamarin addins: 1981a9e7c28d5c3839bb5dc2a0dcaf56fe640906
Build lane: monodevelop-lion-dogfood-vNext

=== Operating System ===

Mac OS X 10.13.1
Darwin 17.2.0 Darwin Kernel Version 17.2.0
    Fri Sep 29 18:27:05 PDT 2017
    root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
Comment 6 Manuel de la Peña [MSFT] 2017-12-15 12:14:47 UTC
@Alex could you check the new releases to see if we solved the issue. I personally cannot longer reproduce it.
Comment 7 Vladimir Abakumov 2017-12-15 12:26:12 UTC
Alex, thank you for your answer!)
Comment 8 Alex 2017-12-15 12:28:51 UTC
Hi Manuel!
The bug has still reproduced on iPhone 7, iOS 11.2
The env used to test is the following:

=== Visual Studio Community 2017 for Mac ===

Version 7.3.2 (build 12)
Installation UUID: f609a2fd-3985-46e9-ac55-eade07b9ad58
Runtime:
	Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010007

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.0
	1.1.1
	1.0.4
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Versions:
	2.0.0
	1.0.3
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

'/Applications/Xamarin Profiler.app' not found

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.iOS ===

Version: 11.6.1.2 (Visual Studio Community)
Hash: 6857dfcc
Branch: xcode9.2
Build date: 2017-12-04 21:20:41-0500

=== Xamarin.Android ===

Version: 8.1.0.25 (Visual Studio Community)
Android SDK: /Users/aserdobintsev/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0 (API level 23)
		8.0 (API level 26)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.Mac ===

Version: 4.0.0.214 (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 703020012
Git revision: 7d0c9d7ad46b125cf4b7bbf9532c0531b6433ce6
Build date: 2017-12-12 14:03:18-05
Xamarin addins: 6dddaa49fbecb2695fcdcd6b712eb269e288518c
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.13.2
Darwin 17.3.0 Darwin Kernel Version 17.3.0
    Thu Nov  9 18:09:22 PST 2017
    root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
Comment 9 Alex 2017-12-15 12:30:20 UTC
Created attachment 26015 [details]
Screenshot of call stack
Comment 10 Manuel de la Peña [MSFT] 2018-01-09 15:13:56 UTC
I managed to confirm the bug with the following env:

=== Visual Studio Community 2017 for Mac ===

Version Preview - Internal Dogfood (7.3.3 build 5)
Installation UUID: 8d12e55e-3489-463f-ac52-8cb4573c5a81
Runtime:
	Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010007

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.0
	1.1.2
	1.0.5
	1.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Versions:
	2.0.0
	1.0.4
	1.0.0-preview2-003121
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.iOS ===

Version: 11.6.1.2 (Visual Studio Community)
Hash: 6857dfcc
Branch: xcode9.2
Build date: 2017-12-04 21:20:41-0500

=== Xamarin.Android ===

Version: 8.1.0.25 (Visual Studio Community)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.Mac ===

Version: 4.0.0.214 (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 703030005
Git revision: b1c2982e201e71ef758866c9ade05f253a8c6f47
Build date: 2017-12-21 11:06:49-05
Xamarin addins: f397ddfbacfb39e60c9cc8d9e410f73faf8c2cbc
Build lane: monodevelop-lion-dogfood-vNext

=== Operating System ===

Mac OS X 10.13.1
Darwin 17.2.0 Darwin Kernel Version 17.2.0
    Fri Sep 29 18:27:05 PDT 2017
    root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
Comment 11 Manuel de la Peña [MSFT] 2018-01-10 16:04:47 UTC
Just to clarify, in order to duplicate this bug I had to retry refreshing the application for about 15 to 20 mins. It is not a bug that can be easily reproduced.
Comment 12 Manuel de la Peña [MSFT] 2018-01-10 16:06:27 UTC
@Alex can you please provide the native version of the application.
Comment 13 Alex 2018-01-11 11:17:42 UTC
@Manuel de la Peña 
What do you mean by 'provide the native version of the application'?
Do you need a native version of the attached "Project to reproduce the bug"?

I can reproduce the bug in about 10-40 seconds. Do you need the video of that?
Comment 14 Manuel de la Peña [MSFT] 2018-01-11 12:18:08 UTC
@Alex yes, I would like to have a objc app that is similar yet works. That way I can take a look at the differences between both.

> I can reproduce the bug in about 10-40 seconds. Do you need the video of that?

No need for the video, I added the note to let other MS developers know not to give up if it takes them longer time. I was testing it in a real iOS 7 device, so I just wanted to make sure that if some else take a look at the issue, they are patient enough :)
Comment 15 Manuel de la Peña [MSFT] 2018-02-08 16:31:25 UTC
Created attachment 26158 [details]
Swift sample application

I have managed to reproduced a thread issue with the attached application. Can you please try in your system and confirm it. If that is the case we should report this upstream.
Comment 16 Alex 2018-02-09 12:07:05 UTC
Created attachment 26159 [details]
TestProtocolWithManyWebViews.zip
Comment 17 Alex 2018-02-09 12:11:06 UTC
@Manuel, Sory for a long absence.

Attached project(Swift sample application) has the other problem. WebViewDelegate is 'unowned(unsafe) open var delegate: UIWebViewDelegate?' so it is released after the end of for block. It is just error in the code. 
Also, there is no registered NSUrlProtocol class in your project, so it hardly can to reproduce the bug.

I've attached the native project (TestProtocolWithManyWebViews.zip) i.e. objc app that is similar yet works.
Comment 18 Manuel de la Peña [MSFT] 2018-02-12 11:11:55 UTC
Oh! Sorry for that mistake. Setting the bug as confirmed and as part of mono.