Bug 37356 - Garbage collector's signals SIGPWR and SIGXCPU are sources of infinite hangs in sockets and in other places
Summary: Garbage collector's signals SIGPWR and SIGXCPU are sources of infinite hangs ...
Status: RESOLVED NORESPONSE
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-01 10:17 UTC by BogdanovKirill
Modified: 2018-03-19 20:20 UTC (History)
3 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description BogdanovKirill 2016-01-01 10:17:14 UTC
For example, just look at here:
https://github.com/mono/mono/blob/master/mono/io-layer/sockets.c#L599
We always check errno's value for EINTR and try to resend data if this signal is caught. But the problem is that when we have set send timeout (typical value is about 5000 ms) to socket and network connection is unexpectedly lost, we could see situation when because of frequent garbage collector signals we will never see timeout error. So, our thread will stay forever in that cycle.

You could check that simple program:
			//this will do some pressure for GC
			ThreadPool.QueueUserWorkItem((st) =>
				{
					while(true)
					{
						var bb = new byte[5 * 10000];
						Thread.Sleep(1);
					}
				}
			);
			
			TcpClient client = new TcpClient ();
			client.Connect ("192.168.100.55", 9999);
			client.ReceiveTimeout = 5000;

			var stream = client.GetStream ();

			while (true) {
				byte[] buff = new byte[1024];
                                //we will stay here forever if network is physically broken now
				int readen = stream.Read (buff, 0, buff.Length);

				if (readen == 0)
					{
						Console.WriteLine("End of stream");
						return;
					}

				Console.WriteLine ("read ok: " + readen);
			}

Also I want to add that this problem is much bigger. Just watch on search result here: https://github.com/mono/mono/search?utf8=%E2%9C%93&q=EINTR&type=Code

Have no idea how to fix it, but may be somebody could give some ideas?