[Mono-dev] StreamReader.ReadToEnd crashes sometimes

cs_eps christian.schmid at eps.ch
Fri Feb 4 08:06:39 EST 2011

Hallo experts!

Once in a while StreamReader.ReadToEnd() crashes with the following stack

Mprotect failed at 0x4621e000 (length 20480) with errno 12

  at (wrapper managed-to-native)
object.__icall_wrapper_mono_array_new_specific (intptr,int) <0xffffffff>
  at System.IO.StreamReader.ReadToEnd () <0x00063>
  at Skywalker.Core.Platform.CPlatformLinux.ExecSync (string,string,string&)
  at Skywalker.Core.Platform.CPlatformArchos5._ReadBattery () <0x0005f>
  at Skywalker.Core.Platform.CPlatformArchos5.get_BatteryLevel () <0x0001b>
  at Skywalker.UserInterface.Controls.CPnlEnvCUBattery.UpdateBatteryState ()
  at (wrapper remoting-invoke-with-check)
Skywalker.UserInterface.Controls.CPnlEnvCUBattery.UpdateBatteryState ()
  at Skywalker.UserInterface.Controls.CEnvStatusBar.OnEnvTimerTick
(object,System.EventArgs) <0x00043>
  at System.Windows.Forms.Timer.OnTick (System.EventArgs) <0x0003b>
  at System.Windows.Forms.Timer.FireTick () <0x0002f>
  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.Timer.FireTick () <0x00067>
  at System.Windows.Forms.XplatUIX11.CheckTimers
(System.Collections.ArrayList,System.DateTime) <0x00313>
  at System.Windows.Forms.XplatUIX11.UpdateMessageQueue
(System.Windows.Forms.XEventQueue) <0x003c3>
  at System.Windows.Forms.XplatUIX11.GetMessage
(object,System.Windows.Forms.MSG&,intptr,int,int) <0x002cf>
  at System.Windows.Forms.XplatUI.GetMessage
(object,System.Windows.Forms.MSG&,intptr,int,int) <0x00067>
  at System.Windows.Forms.Application.RunLoop
(bool,System.Windows.Forms.ApplicationContext) <0x00c1b>
  at System.Windows.Forms.Application.Run
(System.Windows.Forms.ApplicationContext) <0x0005b>
  at System.Windows.Forms.Application.Run (System.Windows.Forms.Form)
  at Skywalker.Program.Main.Program.Main () <0x0007f>
  at (wrapper runtime-invoke) object.runtime_invoke_void
(object,intptr,intptr,intptr) <0x0009f>

Native stacktrace:

    mono [0xeecb8]
    mono [0x134fb4]
    /lib/libc.so.6(__default_rt_sa_restorer_v2+0) [0x4010bb20]
    mono [0x2c391c]
    mono [0x2c3370]
    mono [0x2c978c]
    mono [0x2c9d18]
    mono [0x2c9fdc]
    mono [0x258be0]
    mono(mono_array_new_specific+0x98) [0x258d38]
    mono(mono_array_new_specific+0xc) [0x258cac]
    mono(mono_array_new_specific+0xc) [0x258cac]
    mono(mono_array_new_specific+0xc) [0x258cac]
    mono(mono_array_new_specific+0xc) [0x258cac]

warning: Unable to find libthread_db matching inferior's thread library,
thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library,
thread debugging will not be available.
warning: Unable to find libthread_db matching inferior's thread library,
thread debugging will not be available.
Cannot access memory at address 0x44ef
0x400be3b4 in read () from /lib/libpthread.so.0
* 1 process 26404  0x400be3b4 in read () from /lib/libpthread.so.0

Thread 1 (process 26404):
#0  0x400be3b4 in read () from /lib/libpthread.so.0
#1  0x400bdd94 in ?? () from /lib/libpthread.so.0
#2  0xbede9fcc in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

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

Here the code snippet that causes the exception. Unfortunately we can not
catch it, so the application terminates.
using (Process p = new Process())
                // Redirect the output stream of the child process.
                p.StartInfo.UseShellExecute = false; //true for open
documents with the associated application
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.FileName = p_Process;
                p.StartInfo.Arguments = p_Arguments;

                    if (p.Start() && p.Id > 0)
                        pid = p.Id;

                        _Logger.Debug(string.Format("process {0} {1} started
with pid={2}", p_Process, p_Arguments, pid));

                        // Do not wait for the child process to exit before
                        // reading to the end of its redirected stream.
                        p_Output = p.StandardOutput.ReadToEnd();

                        //wait for completion
                        // fetch the exit code
                        exitCode = p.ExitCode;

                        _Logger.Debug(string.Format("process with pid={0}
exited with code {1}", pid, exitCode));
                        _Logger.Warn(string.Format("process {0} {1} did not
start", p_Process, p_Arguments));
                catch (Exception ex)
                    _Logger.Warn(string.Format("exception in process {0}:
{1} ", p_Process, ex.Message));

Is there a fix for this? or a workaround?

Every help is appreciated!
View this message in context: http://mono.1490590.n4.nabble.com/StreamReader-ReadToEnd-crashes-sometimes-tp3260133p3260133.html
Sent from the Mono - Dev mailing list archive at Nabble.com.

More information about the Mono-devel-list mailing list