提交 e389dac6 编写于 作者: L Ludovic Henry

[IO] Dump handle when we run out of them

When running out of handle, it's hard to know exactly why. Dumping them
will help troubleshoot handle leaks.
上级 526c802c
......@@ -51,6 +51,8 @@ namespace System.IO
public static readonly IntPtr
InvalidHandle = (IntPtr)(-1L);
static bool dump_handles = Environment.GetEnvironmentVariable ("MONO_DUMP_HANDLES_ON_ERROR_TOO_MANY_OPEN_FILES") != null;
// error methods
public static Exception GetException (MonoIOError error)
{
......@@ -89,6 +91,8 @@ namespace System.IO
return new FileNotFoundException (message, path);
case MonoIOError.ERROR_TOO_MANY_OPEN_FILES:
if (dump_handles)
DumpHandles ();
return new IOException ("Too many open files", unchecked((int)0x80070000) | (int)error);
case MonoIOError.ERROR_PATH_NOT_FOUND:
......@@ -599,6 +603,9 @@ namespace System.IO
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static void DumpHandles ();
}
}
......@@ -1252,3 +1252,12 @@ mono_filesize_from_fd (int fd)
}
#endif
void _wapi_handle_dump (void);
void ves_icall_System_IO_MonoIO_DumpHandles (void)
{
#ifndef HOST_WIN32
_wapi_handle_dump ();
#endif
}
......@@ -253,6 +253,9 @@ mono_filesize_from_path (MonoString *path);
extern gint64
mono_filesize_from_fd (int fd);
void
ves_icall_System_IO_MonoIO_DumpHandles (void);
G_END_DECLS
#endif /* _MONO_METADATA_FILEIO_H_ */
......@@ -325,6 +325,7 @@ ICALL(MONOIO_3, "CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_Syst
ICALL(MONOIO_4, "CreatePipe", ves_icall_System_IO_MonoIO_CreatePipe)
ICALL(MONOIO_5, "DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile)
#endif /* !PLATFORM_RO_FS */
ICALL(MONOIO_38, "DumpHandles", ves_icall_System_IO_MonoIO_DumpHandles)
ICALL(MONOIO_34, "DuplicateHandle", ves_icall_System_IO_MonoIO_DuplicateHandle)
ICALL(MONOIO_37, "FindClose", ves_icall_System_IO_MonoIO_FindClose)
ICALL(MONOIO_35, "FindFirst", ves_icall_System_IO_MonoIO_FindFirst)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册