Bug 25419 - Got a SIGSEGV while executing native code. On SetSocketOption, MulticastOption
Summary: Got a SIGSEGV while executing native code. On SetSocketOption, MulticastOption
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.20.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2014-12-16 06:02 UTC by Fedor
Modified: 2016-08-30 21:34 UTC (History)
3 users (show)

Tags: XATriaged
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 FIXED

Description Fedor 2014-12-16 06:02:48 UTC
I`m using IpMulticasting to discover server from android device.

The code on androdi part looks like this:

using(var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp))
{
  EndPoint endpoint = new IPEndPoint(IPAddress.Any, 4567);
  socket.Bind(endpoint);
  socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(ServiceBindings.MulticastIp), IPAddress.Any));
  var buffer = new byte[1024];
  var bytesReceived = socket.ReceiveFrom(buffer, SocketFlags.None, ref endpoint);

  address = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
}

When I`m debugging from Xamarin Studio or running application installed by Xamarin Studio - everything works fine.
But, whenevet I`m creating an apk from "Publish Android Application" menu and having installed this apk on any device it crashes with the following log:

12-16 13:45:41.976  6882  6896 E mono-rt : Stacktrace:

12-16 13:45:41.976  6882  6896 E mono-rt : 

12-16 13:45:41.976  6882  6896 E mono-rt :   at <unknown> <0xffffffff>

12-16 13:45:41.976  6882  6896 E mono-rt :   at (wrapper managed-to-native) System.Net.Sockets.Socket.SetSocketOption_internal (intptr,System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object,byte[],int,int&) <0xffffffff>

12-16 13:45:41.976  6882  6896 E mono-rt :   at System.Net.Sockets.Socket.SetSocketOption (System.Net.Sockets.SocketOptionLevel,System.Net.Sockets.SocketOptionName,object) <0x0017b>

12-16 13:45:41.976  6882  6896 E mono-rt :   at AndroidControlApplication.SplashActivity.DiscoverApiAddress (object,System.ComponentModel.DoWorkEventArgs) <0x00123>

12-16 13:45:41.976  6882  6896 E mono-rt :   at System.ComponentModel.BackgroundWorker.OnDoWork (System.ComponentModel.DoWorkEventArgs) <0x00037>

12-16 13:45:41.976  6882  6896 E mono-rt :   at System.ComponentModel.BackgroundWorker.ProcessWorker (object,System.ComponentModel.AsyncOperation,System.Threading.SendOrPostCallback) <0x00073>

12-16 13:45:41.976  6882  6896 E mono-rt :   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object_object (object,intptr,intptr,intptr) <0xffffffff>

12-16 13:45:41.976  6882  6896 E mono-rt : 

12-16 13:45:41.976  6882  6896 E mono-rt : =================================================================

12-16 13:45:41.976  6882  6896 E mono-rt : Got a SIGSEGV while executing native code. This usually indicates

12-16 13:45:41.976  6882  6896 E mono-rt : a fatal error in the mono runtime or one of the native libraries 

12-16 13:45:41.976  6882  6896 E mono-rt : used by your application.

12-16 13:45:41.976  6882  6896 E mono-rt : =================================================================


So the steps to reproduce would be:

- Create android multicast client in xamarin studio. Run it on device with xamarin studio, verify that everything is working
- Publish android application via xamarin studio, install apk on device (I have tested on adnroid 4.1.2 and 5.0 if it can help) - app will crash on SetSocketOption.

Can you suggest any work around to this problem? For me this bug is of Show-Stopper level.
Comment 1 Greg Munn 2014-12-16 09:46:33 UTC
Quick question, does your application have the INTERNET permission? If yes, are you able to attach a sample project that reproduces this behaviour and paste the details from the about box.
Comment 2 Fedor 2014-12-16 10:31:51 UTC
1) Yes it has INTERNET permission

2) App sample: https://www.dropbox.com/s/b7r3p2vxmlcpk06/AndroidEndpointDiscovery.7z?dl=0
to reproduce just press "Discover server" button. Sorry, for lack of locks and null checks in code - it is just sample. 

3) logcat log after installing from *.apk https://www.dropbox.com/s/1p215rdmrko09u7/logcat.txt?dl=0

4) Did you mean about box of Xamarin Studio? If yes, than here it is:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 39421f25-5638-4533-adc9-1242e6da71b8
Runtime:
	Microsoft .NET 4.0.30319.34209
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Indie Edition)
Android SDK: C:\Users\fedor.reznik\AppData\Local\Android\android-sdk
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 13:26:21-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 3 Greg Munn 2014-12-16 10:37:36 UTC
Thanks for the additional info, from the looks of it, it looks like a runtime issue. Forwarding to the android team,
Comment 4 Udham Singh 2014-12-19 08:56:47 UTC
I have checked this issue with sample app attached in comment 2 and followed the instructions provided in bug description,and observed that when we click on "Discover server" button application is getting crashed.

Steps to reproduce :

1. Publish android application via xamarin studio.
2. Install apk on android device (Samsung Galaxy Note3 android version 4.4.2).
3. Tap application 'AndroidEndpointDiscovery' to open it.
4. Click button 'Discover server' and application is getting crashed with message "Unfortunately, AndroidEndpointDiscovery has stopped."

Adb Logcat : https://gist.github.com/anonymous/3ffd1a20433ee2181255

Environment Info :

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 3235da96-1cb2-43d5-a836-234fd96911c2
Runtime:
	Microsoft .NET 4.0.30319.18449
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.20.0 (Enterprise Edition)
Android SDK: D:\Backup_OldMachine\D Drive\SDK\android-sdk
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.0    (API level 11)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
Java SDK: C:\Program Files\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 13:26:21-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 5 Marek Habersack 2016-08-30 21:34:40 UTC
This issue no longer exists in the current master and cycle8 versions of XA (Cycle 8 is soon to be released)