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: 2018-02-19 11:01 UTC (History)
7 users (show)

See Also:
Tags: bugpool-archive
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.
Comment 6 Roman 2018-01-24 22:25:34 UTC
I have same error on Linux, mono 5.4 and mono 5.8
Comment 7 Bernhard Urban 2018-01-25 13:05:17 UTC
@Roman do you have a stack trace?
Comment 8 Roman 2018-01-25 13:51:06 UTC
Yes, Sir

System.ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStringAnsi (intptr)
at Microsoft.Xna.Framework.Audio.Microphone.PopulateCaptureDevices () [0x0008c] in /media/destructor/Documents/Projects/Вспомогательные/Monogame3.6/MonoGame.Framework/Audio/Microphone.OpenAL.cs:70
at Microsoft.Xna.Framework.Audio.OpenALSoundController..ctor () [0x00040] in /media/destructor/Documents/Projects/Вспомогательные/Monogame3.6/MonoGame.Framework/Audio/OpenALSoundController.cs:122
at Microsoft.Xna.Framework.Audio.OpenALSoundController.get_GetInstance () [0x0000d] in /media/destructor/Documents/Projects/Вспомогательные/Monogame3.6/MonoGame.Framework/Audio/OpenALSoundController.cs:291
at Microsoft.Xna.Framework.SdlGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x000f3] in /media/destructor/Documents/Projects/Вспомогательные/Monogame3.6/MonoGame.Framework/SDL/SDLGamePlatform.cs:73
at Microsoft.Xna.Framework.GamePlatform.PlatformCreate (Microsoft.Xna.Framework.Game game) [0x00001] in /media/destructor/Documents/Projects/Вспомогательные/Monogame3.6/MonoGame.Framework/GamePlatform.Desktop.cs:18
at Microsoft.Xna.Framework.Game..ctor () [0x00225] in /media/destructor/Documents/Projects
Comment 9 Ewan 2018-02-19 11:01:09 UTC
Possibly the same bug but seeing this quite regularly on Mac OS High Sierra 10.13.3

System.ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
  at (wrapper managed-to-native) System.Object:__icall_wrapper_ves_icall_string_new_wrapper (intptr)

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

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