Bug 59916 - get_current_locale_name fails under the load with String conversion error: Illegal byte sequence encounted in the input
Summary: get_current_locale_name fails under the load with String conversion error: Il...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: master
Hardware: PC Mac OS
: --- major
Target Milestone: ---
Assignee: Bernhard Urban
URL:
Depends on:
Blocks:
 
Reported: 2017-10-03 13:28 UTC by Marek Safar
Modified: 2017-11-15 18:57 UTC (History)
5 users (show)

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


Attachments

Description Marek Safar 2017-10-03 13:28:38 UTC
Using following repro (The repro was extracted from various failing builds on Jenkins and Wrench)

using System.Threading;

class X
{
	public static void Main ()
	{
		string res;
		var range = new Thread [10];
		for (int i = 0; i < range.Length; ++i) {
			range[i] = new Thread (l => {
				Thread.Sleep (20 - i);
				res = 1.ToString ();
			});
		}

		foreach (var r in range)
			r.Start ();

		foreach (var r in range)
			r.Join ();
	}
}

Running this in the loop I get occasional crash

System.ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
  at (wrapper managed-to-native) System.Globalization.CultureInfo.get_current_locale_name()
  at System.Globalization.CultureInfo.ConstructCurrentCulture () [0x0000d] in <57d3528b6e84429aa5b942ad54e87ba8>:0
  at System.Globalization.CultureInfo.get_UserDefaultCulture () [0x00000] in <57d3528b6e84429aa5b942ad54e87ba8>:0
  at System.Threading.Thread.GetCurrentCultureNoAppX () [0x00010] in <57d3528b6e84429aa5b942ad54e87ba8>:0
  at System.Threading.Thread.get_CurrentCulture () [0x00000] in <57d3528b6e84429aa5b942ad54e87ba8>:0
  at System.Globalization.NumberFormatInfo.get_CurrentInfo () [0x00005] in <57d3528b6e84429aa5b942ad54e87ba8>:0
  at System.Int32.ToString () [0x00000] in <57d3528b6e84429aa5b942ad54e87ba8>:0
Comment 1 Arsen.Shnurkov 2017-10-26 07:43:50 UTC
I don't know is it related or not, but i have the following exception:

Unhandled Exception:
System.ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStringAnsi (intptr)
  at System.Windows.Forms.XplatUIX11.TranslatePropertyToClipboard (System.IntPtr property) [0x0005f] in /mono-5.4.0.167-abi_x86_64.amd64/mcs/class/System.Windows.Forms/System.Windows.Forms/XplatUIX11.cs:1267
Comment 2 Ludovic Henry 2017-11-08 23:49:21 UTC
I couldn't reproduced with Mono 5.8.0.40 (2017-10/ce494e3d152) after running for 10 000 times. Please reopen if you can reproduce it. Thank you
Comment 3 Marek Safar 2017-11-14 15:33:09 UTC
I can reliably reproduce it on Mono JIT compiler version 5.9.0 (master/05fae5f1fad Mon Nov 13 16:56:57 CET 2017)

See https://gist.github.com/marek-safar/89d78e036ac53e950a11db7380652164
Comment 4 Arsen.Shnurkov 2017-11-14 20:19:53 UTC
"Illegal byte sequence encounted in the input." string is from eglib
https://github.com/mono/eglib/blob/master/src/giconv.c
Comment 5 Bernhard Urban 2017-11-14 21:39:52 UTC
this PR should fix the issue around get_current_locale_name on macOS: https://github.com/mono/mono/pull/6009

@Arsen.Shnurkov: you're running in a different issue, but the reason is likely that the string that you pass contains garbage. In this bug for example, several threads do modifications to a global string. I kindly ask you to open another bug, ideally with instructions on how to reproduce the problem.

Note You need to log in before you can comment on or make changes to this bug.