Bug 37355 - App crashes with SIGSEGV & native stacktrace, but without managed code stacktrace
Summary: App crashes with SIGSEGV & native stacktrace, but without managed code stackt...
Status: RESOLVED INVALID
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2015-12-31 17:05 UTC by Jacek Rużyczka
Modified: 2016-03-04 20:09 UTC (History)
4 users (show)

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


Attachments
DBConnectionHandler (7.30 KB, text/plain)
2016-03-02 18:42 UTC, Jacek Rużyczka
Details
main program (288 bytes, text/plain)
2016-03-02 18:42 UTC, Jacek Rużyczka
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 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 INVALID

Description Jacek Rużyczka 2015-12-31 17:05:47 UTC
I get a SIGSEGV in my Gtk# app every time I reach a line of code with NpgsqlConnection.Open(), which I found out with debug messages: Console.WriteLine() just before this line is executed, right after this line not. As the stacktrace I get only contains a native part and no calltrace of the managed / CLR part of the code, I am slightly puzzled. See this:

Stacktrace:


Native stacktrace:

        mono() [0x4a1015]
        mono() [0x4f398e]
        mono() [0x428bc6]
        /lib64/libpthread.so.0(+0xf890) [0x7f387c670890]
        mono() [0x5aa5c0]
        mono() [0x5759bd]
        mono() [0x577696]
        [0x41bda527]

Debug info from gdb:

[New LWP 6077]
[New LWP 6076]
[New LWP 6075]
[New LWP 6074]
[New LWP 6072]
[New LWP 6071]
[New LWP 6069]
[New LWP 6068]
[New LWP 6065]
[New LWP 6064]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x00007f387c66d408 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  Id   Target Id         Frame 
  11   Thread 0x7f387bbff700 (LWP 6064) "mono" 0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  10   Thread 0x7f38794ec700 (LWP 6065) "Finalizer" 0x00007f387c66f010 in sem_wait () from /lib64/libpthread.so.0
  9    Thread 0x7f386b43d700 (LWP 6068) "gdbus" 0x00007f387c396c5d in poll () from /lib64/libc.so.6
  8    Thread 0x7f386ac3c700 (LWP 6069) "gmain" 0x00007f387c396c5d in poll () from /lib64/libc.so.6
  7    Thread 0x7f385bfff700 (LWP 6071) "pool" 0x00007f387c39b019 in syscall () from /lib64/libc.so.6
  6    Thread 0x7f385587c700 (LWP 6072) "threaded-ml" 0x00007f387c396c5d in poll () from /lib64/libc.so.6
  5    Thread 0x7f3854314700 (LWP 6074) "Timer-Scheduler" 0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  4    Thread 0x7f38540ca700 (LWP 6075) "mono" 0x00007f387c3abde4 in clock_nanosleep () from /lib64/libc.so.6
  3    Thread 0x7f384fdf4700 (LWP 6076) "Threadpool work" 0x00007f387c670489 in waitpid () from /lib64/libpthread.so.0
  2    Thread 0x7f384fbf3700 (LWP 6077) "Threadpool work" 0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 1    Thread 0x7f387d171780 (LWP 6063) "mono" 0x00007f387c66d408 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0

Thread 11 (Thread 0x7f387bbff700 (LWP 6064)):
#0  0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () at /lib64/libpthread.so.0
#1  0x00000000005f87bb in  ()
#2  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#3  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 10 (Thread 0x7f38794ec700 (LWP 6065)):
#0  0x00007f387c66f010 in sem_wait () at /lib64/libpthread.so.0
#1  0x000000000061c916 in mono_sem_wait ()
#2  0x00000000005a1de2 in  ()
#3  0x000000000058491b in  ()
#4  0x00000000006232ae in  ()
#5  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#6  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 9 (Thread 0x7f386b43d700 (LWP 6068)):
#0  0x00007f387c396c5d in poll () at /lib64/libc.so.6
#1  0x00007f3872667be4 in  () at /usr/lib64/libglib-2.0.so.0
#2  0x00007f3872667f0a in g_main_loop_run () at /usr/lib64/libglib-2.0.so.0
#3  0x00007f38730b6946 in  () at /usr/lib64/libgio-2.0.so.0
#4  0x00007f387268cb85 in  () at /usr/lib64/libglib-2.0.so.0
#5  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#6  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 8 (Thread 0x7f386ac3c700 (LWP 6069)):
#0  0x00007f387c396c5d in poll () at /lib64/libc.so.6
#1  0x00007f3872667be4 in  () at /usr/lib64/libglib-2.0.so.0
#2  0x00007f3872667cec in g_main_context_iteration () at /usr/lib64/libglib-2.0.so.0
#3  0x00007f3872667d29 in  () at /usr/lib64/libglib-2.0.so.0
#4  0x00007f387268cb85 in  () at /usr/lib64/libglib-2.0.so.0
#5  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#6  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 7 (Thread 0x7f385bfff700 (LWP 6071)):
#0  0x00007f387c39b019 in syscall () at /lib64/libc.so.6
#1  0x00007f38726a9b2b in g_cond_wait_until () at /usr/lib64/libglib-2.0.so.0
#2  0x00007f387263dc81 in  () at /usr/lib64/libglib-2.0.so.0
#3  0x00007f387263e20b in g_async_queue_timeout_pop () at /usr/lib64/libglib-2.0.so.0
#4  0x00007f387268d5cc in  () at /usr/lib64/libglib-2.0.so.0
#5  0x00007f387268cb85 in  () at /usr/lib64/libglib-2.0.so.0
#6  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#7  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 6 (Thread 0x7f385587c700 (LWP 6072)):
#0  0x00007f387c396c5d in poll () at /lib64/libc.so.6
#1  0x00007f385b1daa41 in  () at /usr/lib64/libpulse.so.0
#2  0x00007f385b1cc2ec in pa_mainloop_poll () at /usr/lib64/libpulse.so.0
#3  0x00007f385b1cc95e in pa_mainloop_iterate () at /usr/lib64/libpulse.so.0
#4  0x00007f385b1cca10 in pa_mainloop_run () at /usr/lib64/libpulse.so.0
#5  0x00007f385b1da9f3 in  () at /usr/lib64/libpulse.so.0
#6  0x00007f385af83808 in  () at /usr/lib64/pulseaudio/libpulsecommon-5.0.so
#7  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#8  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 5 (Thread 0x7f3854314700 (LWP 6074)):
#0  0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () at /lib64/libpthread.so.0
#1  0x00000000005fdbcb in  ()
#2  0x000000000060fbf3 in  ()
#3  0x00000000005843df in  ()
#4  0x000000000058446d in  ()
#5  0x0000000041bd195d in  ()
#6  0x0000000000000000 in  ()

Thread 4 (Thread 0x7f38540ca700 (LWP 6075)):
#0  0x00007f387c3abde4 in clock_nanosleep () at /lib64/libc.so.6
#1  0x0000000000610f30 in  ()
#2  0x0000000000587a41 in  ()
#3  0x000000000058491b in  ()
#4  0x00000000006232ae in  ()
#5  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#6  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 3 (Thread 0x7f384fdf4700 (LWP 6076)):
#0  0x00007f387c670489 in waitpid () at /lib64/libpthread.so.0
#1  0x00000000004a10ee in  ()
#2  0x00000000004f398e in  ()
#3  0x0000000000428bc6 in  ()
#4  0x00007f387c670890 in <signal handler called> () at /lib64/libpthread.so.0
#5  0x00000000005aa5c0 in  ()
#6  0x00000000005759bd in  ()
#7  0x0000000000577696 in  ()
#8  0x0000000041bda527 in  ()
#9  0x00007f3840002550 in  ()
#10 0x00007f384fdf37c0 in  ()
#11 0x00007f387bcec6d0 in  ()
#12 0x00007f384fdf37c0 in  ()
#13 0x00007f387bccc910 in  ()
#14 0x00007f384fdf3958 in  ()
#15 0x0000000041bda4a4 in  ()
#16 0x00007f384fdf34f0 in  ()
#17 0x00007f384fdf33d0 in  ()
#18 0x0000000041bda428 in  ()
#19 0x00007f387bccc910 in  ()
#20 0x0000000000000000 in  ()

Thread 2 (Thread 0x7f384fbf3700 (LWP 6077)):
#0  0x00007f387c66d05f in pthread_cond_wait@@GLIBC_2.3.2 () at /lib64/libpthread.so.0
#1  0x0000000000586df2 in  ()
#2  0x000000000058491b in  ()
#3  0x00000000006232ae in  ()
#4  0x00007f387c6690a4 in start_thread () at /lib64/libpthread.so.0
#5  0x00007f387c39f08d in clone () at /lib64/libc.so.6

Thread 1 (Thread 0x7f387d171780 (LWP 6063)):
#0  0x00007f387c66d408 in pthread_cond_timedwait@@GLIBC_2.3.2 () at /lib64/libpthread.so.0
#1  0x00000000005fd97e in  ()
#2  0x000000000060fa02 in  ()
#3  0x00000000005843df in  ()
#4  0x000000000058446d in  ()
#5  0x0000000041bd195d in  ()
#6  0x00007f387bc16800 in  ()
#7  0x0000000000003a98 in  ()
#8  0x00007f387bc167d8 in  ()
#9  0x0000000000003a98 in  ()
#10 0x0000000000003a98 in  ()
#11 0x00007ffcac386818 in  ()
#12 0x0000000000003a98 in  ()
#13 0x00007ffcac385ad0 in  ()
#14 0x00007ffcac385a40 in  ()
#15 0x00007f387982be8a in  () at /usr/lib/mono/4.5/mscorlib.dll.so
#16 0x00007f387bced3b8 in  ()
#17 0x0000000000000001 in  ()
#18 0x00007f387bced3b8 in  ()
#19 0x0000000041bd4f00 in  ()
#20 0x00007f387bced3b8 in  ()
Python Exception <type 'exceptions.OverflowError'> long too big to convert: 
#21 0xffffffffffffffff in  ()#22 0x00007f387bcec901 in  ()
#23 0x00007f387bc91090 in  ()
#24 0x00007ffcac385e60 in  ()
#25 0x0000000041bd3c56 in  ()
#26 0x0000000000000004 in  ()
#27 0x0000000000000000 in  ()

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

And here is the class which provokes this crash. It's called from within a login window so that there can't be many interferences from another part of the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using Npgsql;
using Npgsql.Logging;
using iwawi.batchjobs;

namespace iwawi
{
	
	///<summary>
	///Encapsulates PostgreSQL database connection parameters
	///(server name, user name etc.) and the connection handler
	///itself. This class also performs the login and logout
	///processes.
	///</summary>
	public class DBConnectionHandler : ICloneable
	{
	
		public IDbConnection conn;
		public readonly int status = 0;
		
		private string    connectionString;
		private short     workstationID;
		private short     departmentID;
		private int       personID;
		private string    userName;
		private string    dbHostName;
		private string    dbInstanceName;
		private string    dbVersion;
		private string [] dbparams;
		private DateTime  loginDate;
		
		private static SortedList<ushort, DBConnectionHandler> handlers = new SortedList<ushort, DBConnectionHandler>();
		private static ushort seq                                       = 1;
		private        ushort myseq                                     = 1;
		
		/// <summary>
		/// Constructor
		/// </summary>
		///<param name="dbparams">Connection parameters</param>
		public DBConnectionHandler(string [] dbparams)
		{
			string hostname = "";
			this.dbparams = dbparams;
			connectionString = "Server=" + dbparams [0]
				+ "; Port=" + dbparams [1] +
				"; Database=" + dbparams [2]
				+ "; Username=" + dbparams [3] +
				"; Password=" + dbparams [4] +
				"; Sslmode=Prefer; TrustServerCertificate=True; Pooling=True; BufferSize=16384";

			this.dbHostName = dbparams [0] + ":" + dbparams [1];
			this.dbInstanceName = dbparams [2];
			this.userName = dbparams [3];

			try {
				conn = new NpgsqlConnection (connectionString);
				hostname = Environment.GetEnvironmentVariable("HOSTNAME");
				if (hostname == null) hostname = Environment.GetEnvironmentVariable("COMPUTERNAME");
				
				hostname = hostname.ToLower();
				conn.Open(); //HERE I GET THE SISSEGV, AND THE APP CRASHES!!

				IDbCommand workstationCommand = conn.CreateCommand();
				workstationCommand.CommandText =
					"select workstation_id from workstations where lower (hostname) = \'"
					+ hostname + "\' and not_in_use = false;";
				IDataReader reader = workstationCommand.ExecuteReader();
				reader.Read();				
				workstationID = (Int16) reader ["workstation_id"];
				reader.Close();
				workstationCommand.Dispose();

				this.status = 2;
				
				IDbCommand userCommand = conn.CreateCommand();
				userCommand.CommandText =
					"select person_id, fk_department_id, now() as login_date, " + 
					"substring(version() for (position (',' in version())) - 1) as db_version"
					+ " from employees where username = \'"
					+ dbparams [3] + "\' and is_inactive = false;";
				reader = userCommand.ExecuteReader();
				reader.Read();
				
				personID     = (int) reader ["person_id"];
				departmentID = (short) reader ["fk_department_id"];
				loginDate    = (DateTime) reader ["login_date"];
				dbVersion    = (reader ["db_version"]).ToString();
				
				reader.Close();
				reader = null;
				
				userCommand.Dispose();
				handlers.Add(seq, this);
				
				this.status = 1;
				myseq       = seq;
				seq++;
			}
			catch (NpgsqlException ex) {
				this.status = -1;
				iwawi.GeneralUseDialog message = new iwawi.GeneralUseDialog("Fehler beim Verbinden mit Datenbank:\n"
				+ ex.Message, "Fehler beim Anmelden",
				Gtk.IconTheme.Default.LoadIcon("gtk-dialog-error", 32, 0), false);
				message.Show();
			}
			
			/* If your client has not been registered in the "workstations" table, THIS will happen. */
			catch (InvalidOperationException ex) {
				String messageString;
				if (status == 2) {
					messageString = "Sie als Benutzer »" + dbparams [3] + "« sind nicht für den Zugriff auf iWAWI freigeschaltet.\n"
					+ "Bitte wenden Sie sich an Ihren Systemadministrator.";
				}
				else {
					messageString = "Ihr PC »" + hostname + "« ist nicht für den Zugriff auf iWAWI freigeschaltet.\n"
					+ "Bitte wenden Sie sich an Ihren Systemadministrator.";
				}

				this.status = -1;
				iwawi.GeneralUseDialog message = new iwawi.GeneralUseDialog(
				messageString, "Fehler beim Anmelden", Gtk.IconTheme.Default.LoadIcon("gtk-dialog-error", 32, 0), true);
				message.Show();
			}
		}

		///<summary>
		///Returns the person ID of the user currently logged in.
		///</summary>
		public int getPersonID ()
		{
			return personID;
		}
		
		///<summary>
		///Returns the department ID of the user currently logged in.
		///</summary>
		public short getDepartmentID ()
		{
			return departmentID;
		}
		
		///<summary>
		///Returns the workstation ID of the client machine.
		///</summary>
		public short getWorkstationID ()
		{
			return workstationID;
		}

		///<summary>
		///Returns the login name of the user currently logged in.
		///</summary>
		public string getUserName ()
		{
			return userName;
		}
		
		///<summary>
		///Returns the host name and TCP port of the database server.
		///</summary>
		public string getDBHostName ()
		{
			return this.dbHostName;
		}
		
		///<summary>
		///Returns the instance name of the database server.
		///</summary>
		public string getDBInstanceName ()
		{
			return this.dbInstanceName;
		}
		
		///<summary>
		///Returns the version number of the database server.
		///</summary>
		public string getDBVersion ()
		{
			return this.dbVersion;
		}
		
		/// <summary>
		/// Returns the database connection parameters.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> array with all the connection parameters.
		/// </returns>
		public string [] getDBParams ()
		{
			return this.dbparams;
		}

		/// <summary>
		/// Returns whether the database connection is SSL-secured, or not.
		/// </summary>
		/// <returns><c>true</c>, if SSL is in use, <c>false</c> otherwise.</returns>
		public bool hasSSL ()
		{
			return ((NpgsqlConnection)this.conn).UseSslStream;
		}

		/// <summary>
		/// Returns the current state of the database connection.
		/// </summary>
		/// <returns>The connection state.</returns>
		public string getConnectionState ()
		{
			return this.conn.State.ToString ();
		}
		
		/// <summary>
		/// Returns the database connection parameters as a secure string.
		/// </summary>
		/// <returns>
		/// A <see cref="EncryptedString[]"/> containing all database connection parameters.
		/// </returns>
		public EncryptedString [] getSecureDBParams ()
		{
			EncryptedString [] str = new EncryptedString [this.dbparams.Length];
			int             i   = 0;
			
			foreach (string param in this.getDBParams()) {
				char [] p = param.ToCharArray();
				EncryptedString s = new EncryptedString(param);
				str [i] = s;
				i++;
			}
			
			return str;
		}
		
		///<summary>
		///Returns the date and time when the current session started.
		///</summary>
		public DateTime getLoginDate ()
		{
			return this.loginDate;
		}
		
		///<summary>
		///Closes the database connection.
		///</summary>
		public void close()
		{
			conn.Close();
			conn = null;
			handlers.Remove(myseq);
		}
		
		/// <summary>
		/// Closes all handlers. Invoke this method when quitting your application, as this
		/// will close stray connections as well.
		/// </summary>
		public static void CloseAll()
		{
			foreach (KeyValuePair<ushort, DBConnectionHandler> e in handlers) {
				e.Value.close();
			}
		}
		
		///<summary>
		///Clones this object.
		///</summary>
		public object Clone()
		{
			if (this.status != 1) {
				throw new DataException("Connection handler not ready for cloning.");
			}
			
			else return new DBConnectionHandler (this.dbparams);
		}
		
		public static DbType GetDbType (Type sysType)
		{
			switch (sysType.ToString()) {
			case "System.String":
				return DbType.String;
			case "System.Int16":
				return DbType.Int16;
			case "System.Int32":
				return DbType.Int32;
			case "System.Int64":
				return DbType.Int64;
			case "System.UInt16":
				return DbType.Int16;
			case "System.UInt32":
				return DbType.Int32;
			case "System.UInt64":
				return DbType.Int64;
			case "System.Single":
				return DbType.Single;
			case "System.Double":
				return DbType.Double;
			case "System.Decimal":
				return DbType.Decimal;
			case "System.Boolean":
				return DbType.Boolean;
			case "System.DateTime":
				return DbType.DateTime;
			case "iwawi.batchjobs.EncryptedString":
				return DbType.String;
			default:
				return DbType.Object;
			}
		}
	}
}

What's wring here? I have already reported this bug to the maintainers of Npgsql, but they suppose it's not triggered by Npgsql itself (maybe 'cause Npgsql is a thin driver without any native code).
Comment 1 Jacek Rużyczka 2016-01-13 18:43:11 UTC
Just a reminder: Has anybody looked into this matter?
Comment 2 Jacek Rużyczka 2016-01-13 19:49:03 UTC
UPDATE: Updating to 4.2.1-6.2 does not help.
Comment 3 Jacek Rużyczka 2016-01-25 20:20:50 UTC
…and 4.2.1-6.9 doesn't work either. :-(
Comment 4 Miguel de Icaza [MSFT] 2016-02-06 15:38:01 UTC
The crash happens on thread 3, not on the UI thread.

There are a few sources that could be responsible for this.

The bindings for the API are broken (Open call), you should try to create a standalone case, with no threading and no UI involved to check that, and run with valgrind.

But I see that you are calling Gtk methods on this Open method, while handling an error.   Given this hint, and given how mysterious the crash is, I am thinking that you might be using Gtk from the non-UI thread, which *will* corrupt your application state.

You might want to check that.
Comment 5 Jacek Rużyczka 2016-02-06 16:11:10 UTC
Hey Miguel & thank you so much for helping me with my issue! ^^

I have already tried out a stand-alone case without any UI bindings, and it worked. What, however, makes this case extremely mysterious is that my code did work before a Mono upgrade from 3.12 to 4.2.0 (see above) and stopped working right after applying the upgrade. Later updates (now I have 4.2.2) did not help.

About the broken binding: I have already reported the issue to the Npgsql guys, but they are almost sure it's not Npgsql itself. See here: https://github.com/npgsql/npgsql/issues/907 I'm now using version 3.0.4 from NuGet.

About calling Gtk# from a non-UI thread: I have already experienced crashes in the context of a callback method (asynchronous pop-up window), which were very hard to reproduce as they sometimes appeared immediately and sometimes after a couple of seconds. After inserting Gtk.Notify(), everything worked fine. In my particular example, the code which seems to cause the crash is encapsulated in a DBConnectionHandler background object, which does not call any UI code.

About the Valgrind test: It's gonna take some time, but I will post the output once I've got it. OK?
Comment 6 Jacek Rużyczka 2016-02-06 16:19:19 UTC
OK, here is a Valgrind output from the stand-alone version consisting of just the DBConnectionHandler and a command-line class with a Main method doing nothing more than creating the handler. It's enormous and hard to understand for me:

jacek@veteran:~/Documents/Projects/dbtest/dbtest/bin/Debug $ valgrind --tool=memcheck --leak-check=yes --db-attach=yes mono dbtest.exe
==6880== 
==6880== Warning: --db-attach is a deprecated feature which will be
==6880==    removed in the next release. Use --vgdb-error=1 instead
==6880== 
==6880== Memcheck, a memory error detector
==6880== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==6880== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==6880== Command: mono dbtest.exe
==6880== 
==6880== Invalid write of size 1
==6880==    at 0x4F60E8: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A20B0: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A3D02: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x429236: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x477F54: mono_main (in /usr/bin/mono-sgen)
==6880==    by 0x5780B04: (below main) (in /lib64/libc-2.19.so)
==6880==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==6880== 
==6880== 
==6880== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n
==6880== 
==6880== Process terminating with default action of signal 11 (SIGSEGV)
==6880==  Access not within mapped region at address 0x8
==6880==    at 0x4F60E8: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A20B0: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A3D02: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x429236: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x477F54: mono_main (in /usr/bin/mono-sgen)
==6880==    by 0x5780B04: (below main) (in /lib64/libc-2.19.so)
==6880==  If you believe this happened as a result of a stack
==6880==  overflow in your program's main thread (unlikely but
==6880==  possible), you can try to increase the size of the
==6880==  main thread stack using the --main-stacksize= flag.
==6880==  The main thread stack size used in this run was 8388608.
==6880== 
==6880== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n
==6880== 
==6880== HEAP SUMMARY:
==6880==     in use at exit: 3,768 bytes in 150 blocks
==6880==   total heap usage: 1,149 allocs, 999 frees, 39,904 bytes allocated
==6880== 
==6880== 56 (16 direct, 40 indirect) bytes in 1 blocks are definitely lost in loss record 57 of 64
==6880==    at 0x4C2B200: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==6880==    by 0x62A3D5: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x62C7E5: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4F60A0: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A20B0: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x4A3D02: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x429236: ??? (in /usr/bin/mono-sgen)
==6880==    by 0x477F54: mono_main (in /usr/bin/mono-sgen)
==6880==    by 0x5780B04: (below main) (in /lib64/libc-2.19.so)
==6880== 
==6880== LEAK SUMMARY:
==6880==    definitely lost: 16 bytes in 1 blocks
==6880==    indirectly lost: 40 bytes in 3 blocks
==6880==      possibly lost: 0 bytes in 0 blocks
==6880==    still reachable: 3,712 bytes in 146 blocks
==6880==         suppressed: 0 bytes in 0 blocks
==6880== Reachable blocks (those to which a pointer was found) are not shown.
==6880== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6880== 
==6880== For counts of detected and suppressed errors, rerun with: -v
==6880== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

Attaching gdb did not work due to missing debuginfos for valgrind, mono-core, and glibc I can't find anywhere. :-(
Comment 7 Miguel de Icaza [MSFT] 2016-02-06 17:19:16 UTC
Gtk.Notify does not help, it merely will change the crashing pattern.

Any use of any Gtk APIs in a non-UI thread will corrupt your application state, the heap and so on.   Once you make that mistake, you will not be able to recover and tracking down the problem will be very hard, the bug will manifest in random ways.

The best thing to do at this point is for you to create a self-contained sample that exhibits still exhibits the bug for someone else to diagnose it, or to audit your code and make sure that no UI calls happen from a background thread.

Sadly, when we built Gtk# we did not think of adding thread checks on every API call, we probably should do that some day.

The Mono upgrade most likely just changed the kind of information that was corrupt and made this more obvious, but it was there all along, you just were lucky enough to not hit it.
Comment 8 Jacek Rużyczka 2016-02-06 17:35:59 UTC
The self-contained sample is not very hard to do as the crash always happens in a very early stage of the program execution. In fact, I create a new DBConnectionHandler when the user has clicked a button inside a Gtk# login window. Once its constructor has been called and the handler returns an OK connection state, the code of the login window creates the main window of the app and closes the login window.

Before the upgrade I have _never_ encountered a crash in this code position, and I started working on this piece of code in 2007. Is it possible that there was some performance optimisation implanted into Mono or Gtk#, which then caused some kinda race condition?
Comment 9 Miguel de Icaza [MSFT] 2016-02-06 17:44:33 UTC
It is very likely that this is the case - the issue has always been present, but masked by an existing implementation.

Mono has gone over a very large upgrade to its stack, very large parts of the class libraries have been replaced by the open sourced Microsoft .NET code.

For now, I will set the bug to NEEDINFO, at this point, this does not look like a Mono bug, it is purely a bug that manifests itself in Mono.   Please re-open if you find a reason to suspect Mono.
Comment 10 Jacek Rużyczka 2016-02-06 20:50:52 UTC
Commenting out the code lines generating the error message popups did _not_ help.
Comment 11 Andres G. Aragoneses 2016-02-07 13:34:51 UTC
Jacek, to rule out the possibility that you may having this problem because of not using the main thread with GTK, as Miguel points out, I recommend you to run your application with gui-thread-check to find out:

https://github.com/slluis/gui-thread-check
Comment 12 Jacek Rużyczka 2016-02-08 20:21:44 UTC
OK, this is the output gui-thread-check gives me:

jacek@veteran:~/Documents/Projects/iwawi/iwawi/bin/Debug $ mono --profile=gui-thread-check iwawi.exe
*** Running with gui-thread-check ***
*** GUI THREAD INITIALIZED: 909891456
Stacktrace:


Native stacktrace:

        mono() [0x4a1835]
        mono() [0x4f41be]
        mono() [0x428bf6]
        /lib64/libpthread.so.0(+0xf890) [0x7ff9358bc890]
        mono() [0x5ab050]
        mono() [0x57629d]
        mono() [0x577f76]
        [0x41699c8c]

Debug info from gdb:

[New LWP 6092]
[New LWP 6091]
[New LWP 6090]
[New LWP 6089]
[New LWP 6088]
[New LWP 6085]
[New LWP 6084]
[New LWP 6083]
[New LWP 6080]
[New LWP 6079]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x00007ff9358b9408 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  Id   Target Id         Frame 
  11   Thread 0x7ff934fff700 (LWP 6079) "mono" 0x00007ff9358b905f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  10   Thread 0x7ff9322eb700 (LWP 6080) "Finalizer" 0x00007ff9358bb010 in sem_wait () from /lib64/libpthread.so.0
  9    Thread 0x7ff92493d700 (LWP 6083) "gdbus" 0x00007ff9355e2c5d in poll () from /lib64/libc.so.6
  8    Thread 0x7ff91ffff700 (LWP 6084) "gmain" 0x00007ff9355e2c5d in poll () from /lib64/libc.so.6
  7    Thread 0x7ff91e027700 (LWP 6085) "pool" 0x00007ff9355e7019 in syscall () from /lib64/libc.so.6
  6    Thread 0x7ff90adbf700 (LWP 6088) "threaded-ml" 0x00007ff9355e2c5d in poll () from /lib64/libc.so.6
  5    Thread 0x7ff9098b2700 (LWP 6089) "Timer-Scheduler" 0x00007ff9358b905f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  4    Thread 0x7ff91c05d700 (LWP 6090) "mono" 0x00007ff9355f7de4 in clock_nanosleep () from /lib64/libc.so.6
  3    Thread 0x7ff9094a6700 (LWP 6091) "Threadpool work" 0x00007ff9358bc489 in waitpid () from /lib64/libpthread.so.0
  2    Thread 0x7ff9092a5700 (LWP 6092) "Threadpool work" 0x00007ff9358b9408 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 1    Thread 0x7ff9363bd780 (LWP 6078) "mono" 0x00007ff9358b9408 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
Comment 13 Andres G. Aragoneses 2016-02-09 08:19:19 UTC
>OK, this is the output gui-thread-check gives me:

gui-thread-check is not reporting any problems, so then this means that the bug is not related to GTK threading.
Comment 14 Jacek Rużyczka 2016-02-09 18:44:54 UTC
So it's not the primary suspect, but what else can it be? Concurrent access to the Npgsql classes (here: NpgsqlConnection) maybe? I can hardly imagine there is any concurrency here 'cause the Open() method is called just at the beginnig of my code…
Comment 15 Jacek Rużyczka 2016-02-13 18:12:35 UTC
After installing a bunch of debuginfo files I get a slightly more informative stacktrace. Again, there is no CLR stacktrace. Here is the trace output for thread 3:

Thread 3 (Thread 0x7f5e66248700 (LWP 4173)):
#0  0x00007f5e8aa65489 in waitpid () at /lib64/libpthread.so.0
#1  0x00000000004a190e in mono_handle_native_sigsegv (signal=signal@entry=11, ctx=ctx@entry=0x7f5e70030ac0, info=info@entry=0x7f5e70030bf0) at mini-exceptions.c:2193
#2  0x00000000004f41be in mono_arch_handle_altstack_exception (sigctx=sigctx@entry=0x7f5e70030ac0, siginfo=siginfo@entry=0x7f5e70030bf0, fault_addr=<optimized out>, stack_ovf=stack_ovf@entry=0) at exceptions-amd64.c:805
#3  0x0000000000428bf6 in mono_sigsegv_signal_handler (_dummy=11, _info=0x7f5e70030bf0, context=0x7f5e70030ac0) at mini-runtime.c:2471
#4  0x00007f5e8aa65890 in <signal handler called> () at /lib64/libpthread.so.0
#5  0x00000000005ab050 in mono_field_static_get_value_for_thread (thread=0x7f5e8a49c530, vt=0x1f90610, field=0x0, value=0x7f5e6624703c) at object.c:3264
#6  0x000000000057629d in get_addrinfo_family_hint () at socket-io.c:649
#7  0x000000000057629d in get_addrinfo_family_hint () at socket-io.c:2364
#8  0x0000000000577f76 in ves_icall_System_Net_Dns_GetHostByName_internal (host=0x7f5e8a0cc368, h_name=0x7f5e66247228, h_aliases=0x7f5e66247230, h_addr_list=0x7f5e66247238) at socket-io.c:2382
#9  0x000000004206e087 in  ()
#10 0x00007f5e50002550 in  ()
#11 0x00007f5e662476c0 in  ()
#12 0x00007f5e8a0ec688 in  ()
#13 0x00007f5e662476c0 in  ()
#14 0x00007f5e8a0cc368 in  ()
#15 0x00007f5e66247858 in  ()
#16 0x000000004206e004 in  ()
#17 0x00007f5e662472f0 in  ()
#18 0x00007f5e662471d0 in  ()
#19 0x000000004206df88 in  ()
#20 0x00007f5e8a0cc368 in  ()
#21 0x0000000000000000 in  ()

Does this mean there is some issue with the ves_icall_System_Net_Dns_GetHostByName_internal proc in socket-io.c? Sorry if my question sounds trivial, but I'm not very proficient in interpreting native stacktraces. :-/
Comment 16 Jacek Rużyczka 2016-02-13 21:38:39 UTC
Is maybe this issue related to my bug? https://gist.github.com/jpasichnyk/cbc091a602239e82f61a
Comment 17 Andres G. Aragoneses 2016-02-15 02:33:37 UTC
> Is maybe this issue related to my bug?

Yes looks like it, because the backtrace is similar. Please create a minimal self-contained testcase (i.e. without linking to statsdsharp or any other refs), and attach it to this bug. Then later we can bring it to the attention to the last person that changed code around that area (i.e., looking at https://github.com/mono/mono/commits/master/mono/metadata/socket-io.c ).
Comment 18 Jacek Rużyczka 2016-02-16 20:44:04 UTC
OK, here is the code which is executed _before_ I get the crash. It sounds much, but in fact, it isn't. I do reference Gtk/Gdk, Npgsql (of course), and Npgsql logging. It's only a small fraction of the app I am developing, but as the crash occurs in a very early step (opening the DB connection), the remainder of the code is irrelevant.:

// project created on 08.05.2007 at 19:26
using System;
using System.IO;
using System.Collections;
using System.Resources;
using Gtk;

namespace iwawi
{
	///<summary>
	///The main class of the iwawi client. Reads out all
	///configuration files and starts the login dialog.
	///</summary>
	class MainClass
	{
		public static void Main (string[] args)
		{
			String homeDirectory = "";
			String platform = "";

			Application.Init ();
			
			IDictionary env = Environment.GetEnvironmentVariables();

			foreach (DictionaryEntry o in env) {
				String key = o.Key.ToString();
				if (key.Equals("OSTYPE") || key.Equals("OS")) {
					platform = o.Value.ToString();
					ApplicationInfo.operatingSystem = platform;
				}
				else if (key.Equals("HOME") || key.Equals("LOCALAPPDATA")) {
					homeDirectory = o.Value.ToString();
				}
			}
			ApplicationInfo.homeDirectory = homeDirectory;
			ApplicationInfo.fileDelimiter = Path.DirectorySeparatorChar.ToString();
			ApplicationInfo.pathDelimiter = Path.PathSeparator.ToString();
			
			String configDirectory    	= homeDirectory + iwawi.ApplicationInfo.fileDelimiter + ".iwawi";
			DirectoryInfo configDir		= new DirectoryInfo (configDirectory);
			String configFilePath       = configDirectory + iwawi.ApplicationInfo.fileDelimiter + "database.properties";
			
			if (!(configDir.Exists && System.IO.File.Exists(configFilePath))) {
				if (!(configDir.Exists)) {
					System.IO.Directory.CreateDirectory(configDirectory);
				}
				createDatabaseProperties (configFilePath);
				GeneralUseDialog message = new
					GeneralUseDialog(
					"Es wurde keine Konfigurationsdatei gefunden.\nDaher wurde ein Skelett unter \n" + configFilePath + "\nerstellt.\nBitte dieses anzupassen und danach iWAWI neu zu starten.",
					Gtk.IconTheme.Default.LoadIcon("gtk-help", 32, 0));
				message.Show();
			}
			else {
				IDictionary databaseProperties = readDatabaseProperties (configFilePath);
				MainWindow win = new MainWindow ();
				win.AddDatabaseNames (databaseProperties);
				win.Show ();
			}
			Application.Run ();
		}
		
		/* Erzeugt eine lokale Konfigurationsdatei. */
		private static void createDatabaseProperties (String configFilePath) {
				StreamWriter sw = new StreamWriter(configFilePath, false);
				sw.AutoFlush = true;
				sw.WriteLine ("# Mandantendatei für iWAWI");
				sw.WriteLine ("# Ein Abschnitt pro Mandant, beginnend mit [Mandant].");
				sw.WriteLine ("# Eine Zeile pro Parameter (z.B. Datenbankname).");
				sw.WriteLine ("# Auskommentieren mit \'#\' am Beginn der Zeile.");
				sw.WriteLine ("# ");
				sw.WriteLine ("[Kurzname für Mandant hier eingeben]");
				sw.WriteLine ("DBHOST=Hostname des Datenbankservers");
				sw.WriteLine ("DBPORT=TCP/IP-Port des Datenbankservers");
				sw.WriteLine ("DBNAME=Name der Datenbankinstanz");
				sw.Close();
		}
		
		/* Liest die lokale Konfigurationsdatei. */
		private static IDictionary readDatabaseProperties (String configFilePath) {
			StreamReader sr = new StreamReader(configFilePath, false);
			String configLine;
			IDictionary databaseProperties, databaseDetails;
			databaseProperties = new Hashtable();
			databaseDetails = new Hashtable();
				while ((configLine = sr.ReadLine()) != null) {
					if (!(configLine.StartsWith("#"))) {
						if (configLine.StartsWith("[")) {
							databaseDetails = new Hashtable ();
							String databaseName = configLine.Substring(1, configLine.IndexOf(']')- 1);
							databaseProperties.Add (databaseName, databaseDetails);
						}
						else {
							if (!(configLine.IndexOf('=') == (-1))) {
								String key   = configLine.Substring(0, configLine.IndexOf('='));
								String value = configLine.Substring(configLine.IndexOf('=') + 1);
								databaseDetails.Add (key, value);
							}
						}
					}
				}
			return (databaseProperties);
		}
	}
}

using Pango;
using System;
using System.Collections;
using Gtk;
using Gdk;
using Npgsql.Logging;
using iwawi;

///<summary>
///The login window.
///</summary>
public partial class MainWindow: Gtk.Window
{
	protected IDictionary     databaseNames;
	private   IEnumerator     ee;
	private   FontDescription statusLabelFont = new FontDescription();
	
	public MainWindow (): base ("")
	{
		this.Build();
		this.appInfoLabel.Text = iwawi.ApplicationInfo.getDescription();
		this.statusLabelFont.Family = "Sans";
		this.statusLabelFont.Weight = Weight.Bold;
		
		this.appInfoLabel.ModifyFg(StateType.Normal,  new Gdk.Color (0xff, 0xff, 0xff));
		this.usernameLabel.ModifyFg(StateType.Normal, new Gdk.Color (0xff, 0xff, 0xff));
		this.passwordLabel.ModifyFg(StateType.Normal, new Gdk.Color (0xff, 0xff, 0xff));
		this.databaseLabel.ModifyFg(StateType.Normal, new Gdk.Color (0xff, 0xff, 0xff));
		this.statusLabel.ModifyFg(StateType.Normal,   new Gdk.Color (0xff, 0xff, 0xff));
		this.statusLabel.ModifyFont(statusLabelFont);
		
		this.ShowAll();
	}
	
	///<summary>
	///true, if this form is locked and the cursor has the
	///shape of an hourglass (Windows) or watch (Linux).
	///</summary>
	public bool Hourglass {

		set {
			if (value == true) {
				this.GdkWindow.Cursor = new Cursor
					(Gdk.CursorType.Watch);
			}
			else {
				this.GdkWindow.Cursor = new Cursor
					(Gdk.CursorType.LeftPtr);
			}
		}
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		this.Destroy ();
		Application.Quit ();
		a.RetVal = true;
	}

	
	/* Click [Cancel] to exit without logging in. */
	protected virtual void OnCancelButtonClicked(object sender, System.EventArgs e)
	{
		this.Destroy ();
		Application.Quit ();
	}
	
	public void AddDatabaseNames(IDictionary databaseNames)
	{
		this.databaseNames = databaseNames;
		String[] names = new String[databaseNames.Count];
		IDictionaryEnumerator e = databaseNames.GetEnumerator();
		
		for (int i=0; i < databaseNames.Count; i++) {
			String [] x = new String [1];
			e.MoveNext();
			names [i] = e.Key.ToString();
			x [0] = names [i];
			databaseCombobox.AppendText(names [i]);
		}
		databaseCombobox.Active = 0;
	}

	/* The [Esc] key activates the [Cancel] button. */
	protected virtual void OnKeyPressedEvent(object o, Gtk.KeyPressEventArgs args)
	{
		for (int i=0; i < args.Args.Length; i++) {
			EventKey ek = (EventKey) args.Args [i];
			if (ek.KeyValue == 65307) {
				this.Destroy();
				Application.Quit();
			}
		}
	}

	protected virtual void OnActivated (object sender, System.EventArgs e)
	{
		this.OnLoginButtonPressedEvent(sender, e);
	}
	
	/* Click [Login]...and look what comes next! */
	protected virtual void OnLoginButtonPressedEvent(object sender, System.EventArgs e)
	{
		this.Hourglass = true;
		this.statusLabel.Text = "Anmeldung läuft…";
		string database = databaseCombobox.ActiveText;
		ApplicationInfo.database = database;
		ee = databaseNames.GetEnumerator();
		string [] dbparams;
		DictionaryEntry d;
		IEnumerator f;
		
		String dbuser = usernameEntry.Text;
		String dbpass = passwordEntry.Text;
		
		if (dbuser.Equals("")) {
			iwawi.GeneralUseDialog m = new iwawi.GeneralUseDialog("Bitte geben Sie Ihren Benutzernamen ein.",
				Gtk.IconTheme.Default.LoadIcon("gtk-dialog-error", 32, 0), false);
			m.Show();
		}
		
		do {
			ee.MoveNext();
			d = (DictionaryEntry) ee.Current;
			IDictionary values = (IDictionary) d.Value;
			f = values.GetEnumerator();
		} while(!(d.Key.Equals(database)));

		dbparams = new string [5];

		while (f.MoveNext()) {
			DictionaryEntry y = (DictionaryEntry) f.Current;
			string key = y.Key.ToString();
			if (key.Equals("DBHOST")) dbparams [0] = y.Value.ToString();
			else if (key.Equals("DBPORT")) dbparams [1] = y.Value.ToString();
			else if (key.Equals("DBNAME")) dbparams [2] = y.Value.ToString();
		}
		
		dbparams [3] = dbuser;
		dbparams [4] = dbpass;

		NpgsqlLogManager.Provider = new NLogLoggingProvider ();
		NpgsqlLogManager.IsParameterLoggingEnabled = true;
		iwawi.DBConnectionHandler conn = new iwawi.DBConnectionHandler (dbparams);

		/* Login OK? Close this window, and open the ApplicationMainWindow! */
		if (conn.status == 1) {
			iwawi.ApplicationBaseWindow baseWindow = new iwawi.ApplicationBaseWindow(database, conn);
			this.Destroy();
			baseWindow.Show();
		}
		/* In case of a login failure, this window remains open! */
		else if (conn.status != (-1)){
			this.Destroy();
		}
		else {
			this.Hourglass        = false;
			this.statusLabel.Text = "Anmeldung fehlgeschlagen. Bitte nochmals versuchen.";
			
			this.statusLabel.ModifyFg(StateType.Normal, new Gdk.Color(0xff, 0x00, 0x00));
		}
	}
}


// This file has been generated by the GUI designer. Do not modify.

public partial class MainWindow
{
	private global::Gtk.Fixed @fixed;
	
	private global::Gtk.Image backgrundImage;
	
	private global::Gtk.Label usernameLabel;
	
	private global::Gtk.Entry usernameEntry;
	
	private global::Gtk.Entry passwordEntry;
	
	private global::Gtk.Label passwordLabel;
	
	private global::Gtk.Label databaseLabel;
	
	private global::Gtk.ComboBox databaseCombobox;
	
	private global::Gtk.Button loginButton;
	
	private global::Gtk.Button cancelButton;
	
	private global::Gtk.Label appInfoLabel;
	
	private global::Gtk.Label statusLabel;

	protected virtual void Build ()
	{
		global::Stetic.Gui.Initialize (this);
		// Widget MainWindow
		this.CanFocus = true;
		this.Name = "MainWindow";
		this.Title = global::Mono.Unix.Catalog.GetString ("iWAWI: Anmeldung");
		this.Icon = global::Gdk.Pixbuf.LoadFromResource ("iwawi.icons.iwawi_32px.png");
		this.TypeHint = ((global::Gdk.WindowTypeHint)(1));
		this.Resizable = false;
		this.AllowShrink = true;
		this.DefaultWidth = 600;
		this.DefaultHeight = 277;
		// Container child MainWindow.Gtk.Container+ContainerChild
		this.@fixed = new global::Gtk.Fixed ();
		this.@fixed.Name = "fixed";
		this.@fixed.HasWindow = false;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.backgrundImage = new global::Gtk.Image ();
		this.backgrundImage.Name = "backgrundImage";
		this.backgrundImage.Pixbuf = new global::Gdk.Pixbuf (global::System.IO.Path.Combine (global::System.AppDomain.CurrentDomain.BaseDirectory, "./iwawi_splashscreen.png"));
		this.@fixed.Add (this.backgrundImage);
		// Container child fixed.Gtk.Fixed+FixedChild
		this.usernameLabel = new global::Gtk.Label ();
		this.usernameLabel.Name = "usernameLabel";
		this.usernameLabel.Xpad = 10;
		this.usernameLabel.Ypad = 10;
		this.usernameLabel.Xalign = 0F;
		this.usernameLabel.Yalign = 0F;
		this.usernameLabel.LabelProp = global::Mono.Unix.Catalog.GetString ("Benutzername");
		this.usernameLabel.UseMarkup = true;
		this.usernameLabel.Justify = ((global::Gtk.Justification)(1));
		this.@fixed.Add (this.usernameLabel);
		global::Gtk.Fixed.FixedChild w2 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.usernameLabel]));
		w2.X = 220;
		w2.Y = 76;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.usernameEntry = new global::Gtk.Entry ();
		this.usernameEntry.CanFocus = true;
		this.usernameEntry.Name = "usernameEntry";
		this.usernameEntry.IsEditable = true;
		this.usernameEntry.WidthChars = 27;
		this.usernameEntry.MaxLength = 25;
		this.usernameEntry.InvisibleChar = '●';
		this.@fixed.Add (this.usernameEntry);
		global::Gtk.Fixed.FixedChild w3 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.usernameEntry]));
		w3.X = 340;
		w3.Y = 81;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.passwordEntry = new global::Gtk.Entry ();
		this.passwordEntry.CanFocus = true;
		this.passwordEntry.Name = "passwordEntry";
		this.passwordEntry.IsEditable = true;
		this.passwordEntry.WidthChars = 27;
		this.passwordEntry.MaxLength = 25;
		this.passwordEntry.Visibility = false;
		this.passwordEntry.InvisibleChar = '●';
		this.@fixed.Add (this.passwordEntry);
		global::Gtk.Fixed.FixedChild w4 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.passwordEntry]));
		w4.X = 340;
		w4.Y = 121;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.passwordLabel = new global::Gtk.Label ();
		this.passwordLabel.Name = "passwordLabel";
		this.passwordLabel.Xpad = 10;
		this.passwordLabel.Ypad = 10;
		this.passwordLabel.Xalign = 0F;
		this.passwordLabel.Yalign = 0F;
		this.passwordLabel.LabelProp = global::Mono.Unix.Catalog.GetString ("Passwort");
		this.passwordLabel.UseMarkup = true;
		this.@fixed.Add (this.passwordLabel);
		global::Gtk.Fixed.FixedChild w5 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.passwordLabel]));
		w5.X = 220;
		w5.Y = 116;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.databaseLabel = new global::Gtk.Label ();
		this.databaseLabel.Name = "databaseLabel";
		this.databaseLabel.Xpad = 10;
		this.databaseLabel.Ypad = 10;
		this.databaseLabel.Xalign = 0F;
		this.databaseLabel.Yalign = 0F;
		this.databaseLabel.LabelProp = global::Mono.Unix.Catalog.GetString ("Mandant");
		this.databaseLabel.UseMarkup = true;
		this.@fixed.Add (this.databaseLabel);
		global::Gtk.Fixed.FixedChild w6 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.databaseLabel]));
		w6.X = 220;
		w6.Y = 156;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.databaseCombobox = global::Gtk.ComboBox.NewText ();
		this.databaseCombobox.WidthRequest = 225;
		this.databaseCombobox.Name = "databaseCombobox";
		this.@fixed.Add (this.databaseCombobox);
		global::Gtk.Fixed.FixedChild w7 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.databaseCombobox]));
		w7.X = 340;
		w7.Y = 161;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.loginButton = new global::Gtk.Button ();
		this.loginButton.WidthRequest = 140;
		this.loginButton.HeightRequest = 60;
		this.loginButton.CanFocus = true;
		this.loginButton.Name = "loginButton";
		this.loginButton.UseUnderline = true;
		this.loginButton.BorderWidth = ((uint)(10));
		this.loginButton.Label = global::Mono.Unix.Catalog.GetString ("Anmelden");
		global::Gtk.Image w8 = new global::Gtk.Image ();
		w8.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-apply", global::Gtk.IconSize.Menu);
		this.loginButton.Image = w8;
		this.@fixed.Add (this.loginButton);
		global::Gtk.Fixed.FixedChild w9 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.loginButton]));
		w9.X = 220;
		w9.Y = 190;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.cancelButton = new global::Gtk.Button ();
		this.cancelButton.WidthRequest = 120;
		this.cancelButton.HeightRequest = 40;
		this.cancelButton.CanFocus = true;
		this.cancelButton.Name = "cancelButton";
		this.cancelButton.UseUnderline = true;
		this.cancelButton.Label = global::Mono.Unix.Catalog.GetString ("Abbrechen");
		global::Gtk.Image w10 = new global::Gtk.Image ();
		w10.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-cancel", global::Gtk.IconSize.Menu);
		this.cancelButton.Image = w10;
		this.@fixed.Add (this.cancelButton);
		global::Gtk.Fixed.FixedChild w11 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.cancelButton]));
		w11.X = 445;
		w11.Y = 200;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.appInfoLabel = new global::Gtk.Label ();
		this.appInfoLabel.Name = "appInfoLabel";
		this.@fixed.Add (this.appInfoLabel);
		global::Gtk.Fixed.FixedChild w12 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.appInfoLabel]));
		w12.X = 230;
		w12.Y = 15;
		// Container child fixed.Gtk.Fixed+FixedChild
		this.statusLabel = new global::Gtk.Label ();
		this.statusLabel.Name = "statusLabel";
		this.statusLabel.LabelProp = global::Mono.Unix.Catalog.GetString ("Bitte melden Sie sich an.");
		this.statusLabel.Justify = ((global::Gtk.Justification)(2));
		this.statusLabel.WidthChars = 80;
		this.@fixed.Add (this.statusLabel);
		global::Gtk.Fixed.FixedChild w13 = ((global::Gtk.Fixed.FixedChild)(this.@fixed [this.statusLabel]));
		w13.X = 20;
		w13.Y = 250;
		this.Add (this.@fixed);
		if ((this.Child != null)) {
			this.Child.ShowAll ();
		}
		this.Show ();
		this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
		this.usernameEntry.KeyPressEvent += new global::Gtk.KeyPressEventHandler (this.OnKeyPressedEvent);
		this.usernameEntry.Activated += new global::System.EventHandler (this.OnActivated);
		this.passwordEntry.KeyPressEvent += new global::Gtk.KeyPressEventHandler (this.OnKeyPressedEvent);
		this.passwordEntry.Activated += new global::System.EventHandler (this.OnActivated);
		this.databaseCombobox.KeyPressEvent += new global::Gtk.KeyPressEventHandler (this.OnKeyPressedEvent);
		this.loginButton.Clicked += new global::System.EventHandler (this.OnLoginButtonPressedEvent);
		this.cancelButton.Clicked += new global::System.EventHandler (this.OnCancelButtonClicked);
	}
}


using System;
using Gtk;

namespace iwawi
{
	
	
	public partial class GeneralUseDialog : Gtk.Dialog
	{
		private bool isKiller;
		
		public GeneralUseDialog(string labelText, string title, Gdk.Pixbuf icon, bool isKiller)
		{
			this.isKiller = isKiller;
			this.Build();
			messageLabel.Text = labelText;
			image8.Pixbuf = icon;
			this.Title = title;
		}

		public GeneralUseDialog(string labelText, Gdk.Pixbuf icon, bool isKiller)
		{
			this.isKiller = isKiller;
			this.Build();
			messageLabel.Text = labelText;
			image8.Pixbuf = icon;
		}

		public GeneralUseDialog(string labelText, Gdk.Pixbuf icon)
		{
			this.isKiller = true;
			this.Build();
			messageLabel.Text = labelText;
			image8.Pixbuf = icon;
		}

		protected virtual void onOkButtonClicked(object sender, System.EventArgs e)
		{
			this.Destroy();
			if (isKiller) Application.Quit();
		}
	}
}


// This file has been generated by the GUI designer. Do not modify.
namespace iwawi
{
	public partial class GeneralUseDialog
	{
		private global::Gtk.HPaned messagePane;
		
		private global::Gtk.Image image8;
		
		private global::Gtk.Label messageLabel;
		
		private global::Gtk.Button okButton;

		protected virtual void Build ()
		{
			global::Stetic.Gui.Initialize (this);
			// Widget iwawi.GeneralUseDialog
			this.Events = ((global::Gdk.EventMask)(256));
			this.Name = "iwawi.GeneralUseDialog";
			this.Title = global::Mono.Unix.Catalog.GetString ("Hinweis");
			this.Icon = global::Gdk.Pixbuf.LoadFromResource ("iwawi.icons.iwawi_32px.png");
			this.WindowPosition = ((global::Gtk.WindowPosition)(4));
			this.Modal = true;
			this.Resizable = false;
			this.AllowGrow = false;
			this.DefaultWidth = 180;
			this.DefaultHeight = 60;
			// Internal child iwawi.GeneralUseDialog.VBox
			global::Gtk.VBox w1 = this.VBox;
			w1.Events = ((global::Gdk.EventMask)(256));
			w1.Name = "dialog_VBox";
			w1.BorderWidth = ((uint)(2));
			// Container child dialog_VBox.Gtk.Box+BoxChild
			this.messagePane = new global::Gtk.HPaned ();
			this.messagePane.CanFocus = true;
			this.messagePane.Name = "messagePane";
			this.messagePane.Position = 48;
			this.messagePane.BorderWidth = ((uint)(10));
			// Container child messagePane.Gtk.Paned+PanedChild
			this.image8 = new global::Gtk.Image ();
			this.image8.WidthRequest = 48;
			this.image8.HeightRequest = 48;
			this.image8.Name = "image8";
			this.image8.Xpad = 5;
			this.image8.Ypad = 5;
			this.messagePane.Add (this.image8);
			global::Gtk.Paned.PanedChild w2 = ((global::Gtk.Paned.PanedChild)(this.messagePane [this.image8]));
			w2.Resize = false;
			w2.Shrink = false;
			// Container child messagePane.Gtk.Paned+PanedChild
			this.messageLabel = new global::Gtk.Label ();
			this.messageLabel.Name = "messageLabel";
			this.messageLabel.Xpad = 5;
			this.messageLabel.Ypad = 5;
			this.messageLabel.UseMarkup = true;
			this.messagePane.Add (this.messageLabel);
			w1.Add (this.messagePane);
			global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(w1 [this.messagePane]));
			w4.Position = 0;
			w4.Expand = false;
			w4.Fill = false;
			// Internal child iwawi.GeneralUseDialog.ActionArea
			global::Gtk.HButtonBox w5 = this.ActionArea;
			w5.Events = ((global::Gdk.EventMask)(256));
			w5.Name = "iwawi.GeneralUseDialog_ActionArea";
			w5.Spacing = 6;
			w5.BorderWidth = ((uint)(5));
			w5.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4));
			// Container child iwawi.GeneralUseDialog_ActionArea.Gtk.ButtonBox+ButtonBoxChild
			this.okButton = new global::Gtk.Button ();
			this.okButton.CanDefault = true;
			this.okButton.CanFocus = true;
			this.okButton.Name = "okButton";
			this.okButton.UseUnderline = true;
			this.okButton.BorderWidth = ((uint)(10));
			this.okButton.Label = global::Mono.Unix.Catalog.GetString ("OK");
			global::Gtk.Image w6 = new global::Gtk.Image ();
			w6.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-apply", global::Gtk.IconSize.Menu);
			this.okButton.Image = w6;
			this.AddActionWidget (this.okButton, 0);
			global::Gtk.ButtonBox.ButtonBoxChild w7 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w5 [this.okButton]));
			w7.Expand = false;
			w7.Fill = false;
			if ((this.Child != null)) {
				this.Child.ShowAll ();
			}
			this.Show ();
			this.okButton.Clicked += new global::System.EventHandler (this.onOkButtonClicked);
		}
	}
}

You can cut out all lines where an ApplicationBaseWindow appears (it's a very important part of the app, but the crash occurs before it's built). For the png graphics you can use placeholders.
Comment 19 Andres G. Aragoneses 2016-02-17 02:10:07 UTC
> You can cut out all lines where...

That's the job of "creating a minimal testcase" :) Please start reducing the code bit by bit until you find it doesn't crash anymore, then you will have found the culprit.
Comment 20 Jacek Rużyczka 2016-02-18 20:05:11 UTC
OK, I've got some news. I removed everything GUI-related from Main.cs (so that only Main and DBConnectionHandler are needed) and still get the crash with the same native stacktrace. See here:

// project created on 08.05.2007 at 19:26
using System;
using System.IO;
using System.Collections;
using System.Resources;
using Gtk;

namespace iwawi
{
	///<summary>
	///The main class of the iwawi client. Reads out all
	///configuration files and starts the login dialog.
	///</summary>
	class MainClass
	{
		public static void Main (string[] args)
		{
			String homeDirectory = "/home/jacek";
			String platform = "";

			//Application.Init ();
			
			/*IDictionary env = Environment.GetEnvironmentVariables();

			foreach (DictionaryEntry o in env) {
				String key = o.Key.ToString();
				if (key.Equals("OSTYPE") || key.Equals("OS")) {
					platform = o.Value.ToString();
					ApplicationInfo.operatingSystem = platform;
				}
				else if (key.Equals("HOME") || key.Equals("LOCALAPPDATA")) {
					homeDirectory = o.Value.ToString();
				}
			}*/

			ApplicationInfo.homeDirectory = homeDirectory;
			ApplicationInfo.fileDelimiter = Path.DirectorySeparatorChar.ToString();
			ApplicationInfo.pathDelimiter = Path.PathSeparator.ToString();
			
			String configDirectory    	= homeDirectory + iwawi.ApplicationInfo.fileDelimiter + ".iwawi";
			DirectoryInfo configDir		= new DirectoryInfo (configDirectory);
			String configFilePath       = configDirectory + iwawi.ApplicationInfo.fileDelimiter + "database.properties";
			
			if (!(configDir.Exists && System.IO.File.Exists(configFilePath))) {
				/*if (!(configDir.Exists)) {
					System.IO.Directory.CreateDirectory(configDirectory);
				}
				createDatabaseProperties (configFilePath);
				GeneralUseDialog message = new
					GeneralUseDialog(
					"Es wurde keine Konfigurationsdatei gefunden.\nDaher wurde ein Skelett unter \n" + configFilePath + "\nerstellt.\nBitte dieses anzupassen und danach iWAWI neu zu starten.",
					Gtk.IconTheme.Default.LoadIcon("gtk-help", 32, 0));
				message.Show();*/
			}
			else {
				//IDictionary databaseProperties = readDatabaseProperties (configFilePath);
				//MainWindow win = new MainWindow ();
				//win.AddDatabaseNames (databaseProperties);
				//win.Show ();

				Console.WriteLine ("¤¤ 1 ¤¤");
				DBConnectionHandler handler = new DBConnectionHandler (new string[5] {"valen", "7575", "iwawi", "jacek", "BD4hES"});
				Console.WriteLine ("¤¤ 2 ¤¤");
			}

			//Application.Run ();
		}
		
		/* Erzeugt eine lokale Konfigurationsdatei. */
		private static void createDatabaseProperties (String configFilePath) {
				StreamWriter sw = new StreamWriter(configFilePath, false);
				sw.AutoFlush = true;
				sw.WriteLine ("# Mandantendatei für iWAWI");
				sw.WriteLine ("# Ein Abschnitt pro Mandant, beginnend mit [Mandant].");
				sw.WriteLine ("# Eine Zeile pro Parameter (z.B. Datenbankname).");
				sw.WriteLine ("# Auskommentieren mit \'#\' am Beginn der Zeile.");
				sw.WriteLine ("# ");
				sw.WriteLine ("[Kurzname für Mandant hier eingeben]");
				sw.WriteLine ("DBHOST=Hostname des Datenbankservers");
				sw.WriteLine ("DBPORT=TCP/IP-Port des Datenbankservers");
				sw.WriteLine ("DBNAME=Name der Datenbankinstanz");
				sw.Close();
		}
		
		/* Liest die lokale Konfigurationsdatei. */
		private static IDictionary readDatabaseProperties (String configFilePath) {
			StreamReader sr = new StreamReader(configFilePath, false);
			String configLine;
			IDictionary databaseProperties, databaseDetails;
			databaseProperties = new Hashtable();
			databaseDetails = new Hashtable();
				while ((configLine = sr.ReadLine()) != null) {
					if (!(configLine.StartsWith("#"))) {
						if (configLine.StartsWith("[")) {
							databaseDetails = new Hashtable ();
							String databaseName = configLine.Substring(1, configLine.IndexOf(']')- 1);
							databaseProperties.Add (databaseName, databaseDetails);
						}
						else {
							if (!(configLine.IndexOf('=') == (-1))) {
								String key   = configLine.Substring(0, configLine.IndexOf('='));
								String value = configLine.Substring(configLine.IndexOf('=') + 1);
								databaseDetails.Add (key, value);
							}
						}
					}
				}
			return (databaseProperties);
		}
	}
}

The crash happens exactly between the ¤¤ 1 ¤¤ and ¤¤ 2 ¤¤ tracers.
Comment 21 Jacek Rużyczka 2016-02-18 20:23:56 UTC
And just to clarify: When I remove the DBConnectionHandler call, I also reach tracer ¤¤ 2 ¤¤ and don't crash.
Comment 22 Andres G. Aragoneses 2016-02-19 03:52:39 UTC
That's good news Jacek.

However, I've tried to replicate the problem on my end, and I cannot compile your code:
Error: The type or namespace name 'DBConnectionHandler' could not be found (are you missing a using directive or an assembly reference?)	
Error: The type or namespace name 'ApplicationInfo' does not exist in the namespace 'iwawi' (are you missing an assembly reference?)	

So please, just attach the testcase in a .cs file, removing commented code, and adding the sources for the DBConnectionHandler and ApplicationInfo classes above. And advice how to compile the code (i.e. any DbDriver references needed?.
Comment 23 Jacek Rużyczka 2016-02-19 20:39:53 UTC
About external references: You will need a fresh version of Npgsql and Npgsql.Logging. It's best to get them via NuGet as packagers seem to have forgotten .net libs entirely.

For the DBConnectionHandler please see above.

ApplicationInfo? Just a bunch of properties without real logic. Here you are:

using Gdk;
using System;

namespace iwawi
{
	
	///<summary>
	///Static class containing various information about iWAWI.
	///</summary>
	public static class ApplicationInfo
	{
		public static string homeDirectory   = "";
		public static string fileDelimiter   = "";
		public static string pathDelimiter   = "";
		public static string database        = "";
		public static string operatingSystem = "";
		
		public static readonly string language           = "DE";
		public static readonly string moneyFormat        = "###,###,##0.00";
		public static readonly string exchangeRateFormat = "#0.0000";
		public static readonly string dimensionFormat    = "#0.000";
		public static readonly string integerFormat      = "#0";
		public static readonly string dateFormat         = "DD.MM.YYYY";
		public static readonly string dateTimeFormat     = "DD.MM.YYYY HH24:MI:SS";
		public static readonly string intervalFormat     = "DDD Tage";
		public static readonly string version            = "0.0.0";
		public static readonly int    iWAWIAppID         = 3;
		public static readonly char   period             = ',';
		public static readonly char   barcodeSeparator   = 'ß';
		public static readonly char   csvSeparator       = ';';
		
		private static string webBrowser = "";
		private static string softPhone  = "";
		private static string mailClient = "";
		
		public static Color HighlightColor {
			get {
				return new Color (0x00, 0x80, 0x00);
			}
		}
		
		public static string WebBrowser {
			get {
				return webBrowser;
			}
			set {
				webBrowser = value;
			}
		}
		
		public static string SoftPhone {
			get {
				return softPhone;
			}
			set {
				softPhone = value;
			}
		}
		
		public static string MailClient {
			get {
				return mailClient;
			}
			set {
				mailClient = value;
			}
		}
		
		public static string getDescription()
		{
			return("Version 0.0.0\n© 2012 by Jacek Rużyczka");
		}
	}
}
Comment 24 Jacek Rużyczka 2016-03-01 21:04:03 UTC
Is there any progress in this matter? Thank you.
Comment 25 Miguel de Icaza [MSFT] 2016-03-01 21:49:09 UTC
Please follow the direction on #22, but to re-iterate: create a minimal, self-contained, test case that exhibits the problem.

At this point, everything points towards being an error on your end, not on Gtk, not on Mono.
Comment 26 Andres G. Aragoneses 2016-03-02 06:52:53 UTC
Yes please. To be absolutely clear: don't copy and paste code in a comment here, just attach a file, a .cs file. Thanks
Comment 27 Jacek Rużyczka 2016-03-02 18:41:34 UTC
@Miguel: I have already created such a testcase. See the entries above (#23 is just a supplement to make it compileable). But when I write a minimal code snippet which just creates a DBConnectionHandler (see attachment), the error does not occur. However, if I strip down my solution so that it doesn't call any GUI code, I have no clue on how to get rid of the crash. See also entry #15, line #8, which clearly states that the crash occurs in a native part of the System.Net package.

@Andres: It's really hard to find the attach-a-file feature in Bugzilla. Somebody should really invest in its usability.
Comment 28 Jacek Rużyczka 2016-03-02 18:42:19 UTC
Created attachment 15228 [details]
DBConnectionHandler
Comment 29 Jacek Rużyczka 2016-03-02 18:42:38 UTC
Created attachment 15229 [details]
main program
Comment 30 Miguel de Icaza [MSFT] 2016-03-04 03:06:55 UTC
Please do not reopen this bug until you have a self-contained (zip file with a compilable solution) test case showing the issue.
Comment 31 Jacek Rużyczka 2016-03-04 20:09:58 UTC
Ermmmm…the two .cs files I attached ARE the self-contained example. The only thing you needa install beforehand is the Npgsql driver (get v.3.0.5 from NuGet).