Home All Groups Group Topic Archive Search About

Deadlock in XmlSerializer when using RedirectStandardInput

Author
15 Feb 2007 7:04 PM
MinerDev
I have encountered a situation where a thread (say, thread-1) blocks for 10
minutes in an XmlSerializer constructor. This occurs when another thread
(say, thread-2) is blocked in a call to Console.ReadLine and the process was
created using System.Diagnostics.Process with RedirectStandardInput = true.
In this situation not only does thread-1 block for 10 min in the
XmlSerializer constructor, but will hang indefinitely when creating a COM
object.

The problem started occuring after migrating our application to .NET v2.0.

I found a forum post where some other developers have run into the exact
same problem. Please see this link:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=188895&SiteID=1 (it
also includes a reproducible testcase)

Is anyone aware of a decent workaround to this issue (or a fix available
..NET 2.0)? I seems that this problem greatly limits the usefulness of stdin
redirection.

BACKGROUND INFO

We need to run multiple instances of an console application (it runs until
told to stop). Since we need to run more than one process on a single machine
it did not make sense to make the application a windows service. Instead, we
developed a windows services that spawns these (child) application processes.
Using the System.Diagnostics.Process class we can not only spawn the process,
but also interact with it via stdin and stdout.

OTHER NOTES (not-so-nice workarounds)

It appears that the XmlSerializer hangs in the call to csc.exe (you can see
this child process using ProcessExplorer). I can get around this problem by
sgen'ing the assembly which eliminates the need for spawning csc.exe at
runtime. However, this doesn't fix the problem with creating COM objects.

Another workaround i've seen (see forum post mentioned above) is to not call
Console.ReadLine() in the child process. However, I need this call in order
to process interactive commandline input. Also note the call to ReadLine is
on an MTA thread to avoid STA "pumping" issues, so the deadlock/contention is
occuring on some other resource.

Author
16 Feb 2007 2:56 AM
Walter Wang [MSFT]
Hi,

I've been able to reproduce the issue on XP and it indeed works ok on
Vista. Since I've also installed .NET 3.0 on XP, it's unlikely can be fixed
by installing .NET 3.0 as conclued in the forum post you mentioned.

I'm currently consulting this question in our internal discussion list to
see if there's any hotfix for it on pre-Vista OS. I'll get back to you as
soon as I get updated information. Thank you for your patience and
understanding.

Sincerely,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
23 Feb 2007 2:18 AM
Walter Wang [MSFT]
Hi,

I've sent an email to you on Feb. 20. Since I didn't received your reply
yet I'm wondering if the email address is correct or not. Would you please
send me an email when you see this? Thank you.

Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
1 Mar 2007 7:29 AM
Luke Zhang [MSFT]
Hello,

I am reviewing this post. I found Walter has reproduced the and want to
involve more resource to find a proper solution on this issue. To better
communicate on this issue and find a final solution, would you please let
us know your actual email address? To get my email, please remove "online"
from my display email.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
1 Mar 2007 2:57 PM
Hans-Jürgen Arbogast
Hello,

I am concerned by a very similar deadlock. I start a console-application via
Process.Start (RedirectStandardInput = true). The console application
executes a Console.Readline. In another thread, the program accesses a
SingleThreaded COM componente. Accessing the COM component deadlocks.

I am wondering how to fix this. If I omit the Console.ReadLine call, the
code does not deadlock.

Can anybody please explain, what is going on here.

Kind Regards,
Hans-Jürgen.


  ntdll.dll!_KiFastSystemCallRet@0()
  ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc bytes
  kernel32.dll!_WaitForSingleObjectEx@12()  + 0x8b bytes
  kernel32.dll!_WaitForSingleObject@8()  + 0x12 bytes
  ole32.dll!GetToSTA()  + 0x4e bytes
  ole32.dll!CRpcChannelBuffer::SwitchAptAndDispatchCall()  + 0xccf bytes
  ole32.dll!CRpcChannelBuffer::SendReceive2()  + 0x76 bytes
  ole32.dll!CAptRpcChnl::SendReceive()  + 0x46 bytes
  ole32.dll!CCtxComChnl::SendReceive()  + 0x43 bytes
  rpcrt4.dll!_NdrProxySendReceive@8()  + 0x40 bytes
  rpcrt4.dll!_NdrClientCall2()  + 0x9dc bytes
  rpcrt4.dll!_ObjectStublessClient@8()  + 0x5d bytes
  rpcrt4.dll!_ObjectStubless@0()  + 0xf bytes
  ole32.dll!CStdMarshal::Begin_RemQIAndUnmarshal1()  + 0x91 bytes
  ole32.dll!CStdMarshal::Begin_QueryRemoteInterfaces()  + 0x37 bytes
  ole32.dll!CStdMarshal::QueryRemoteInterfaces()  + 0x37 bytes
  ole32.dll!CStdIdentity::CInternalUnk::QueryMultipleInterfaces()  + 0xce65
bytes
  ole32.dll!CStdIdentity::CInternalUnk::QueryInterface()  + 0x30 bytes
  [Managed to Native Transition]
Show quote
>>>... here is my code, accessing the COM object.

"Luke Zhang [MSFT]" <lukez***@online.microsoft.com> schrieb im Newsbeitrag
news:kKU6yN9WHHA.2352@TK2MSFTNGHUB02.phx.gbl...
> Hello,
>
> I am reviewing this post. I found Walter has reproduced the and want to
> involve more resource to find a proper solution on this issue. To better
> communicate on this issue and find a final solution, would you please let
> us know your actual email address? To get my email, please remove "online"
> from my display email.
>
> Sincerely,
>
> Luke Zhang
>
> Microsoft Online Community Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>
Author
1 Mar 2007 3:00 PM
Hans-Jürgen Arbogast
Oh, excuse me, I forget to mention, that I attached a unmanaged call-stack
of the point where the code is freezing.


Show quote
"Hans-Jürgen Arbogast" <tin@community.nospam> schrieb im Newsbeitrag
news:ejhUiGBXHHA.1180@TK2MSFTNGP05.phx.gbl...
> Hello,
>
> I am concerned by a very similar deadlock. I start a console-application
> via Process.Start (RedirectStandardInput = true). The console application
> executes a Console.Readline. In another thread, the program accesses a
> SingleThreaded COM componente. Accessing the COM component deadlocks.
>
> I am wondering how to fix this. If I omit the Console.ReadLine call, the
> code does not deadlock.
>
> Can anybody please explain, what is going on here.
>
> Kind Regards,
> Hans-Jürgen.
>
>
>  ntdll.dll!_KiFastSystemCallRet@0()
>  ntdll.dll!_ZwWaitForSingleObject@12()  + 0xc bytes
>  kernel32.dll!_WaitForSingleObjectEx@12()  + 0x8b bytes
>  kernel32.dll!_WaitForSingleObject@8()  + 0x12 bytes
>  ole32.dll!GetToSTA()  + 0x4e bytes
>  ole32.dll!CRpcChannelBuffer::SwitchAptAndDispatchCall()  + 0xccf bytes
>  ole32.dll!CRpcChannelBuffer::SendReceive2()  + 0x76 bytes
>  ole32.dll!CAptRpcChnl::SendReceive()  + 0x46 bytes
>  ole32.dll!CCtxComChnl::SendReceive()  + 0x43 bytes
>  rpcrt4.dll!_NdrProxySendReceive@8()  + 0x40 bytes
>  rpcrt4.dll!_NdrClientCall2()  + 0x9dc bytes
>  rpcrt4.dll!_ObjectStublessClient@8()  + 0x5d bytes
>  rpcrt4.dll!_ObjectStubless@0()  + 0xf bytes
>  ole32.dll!CStdMarshal::Begin_RemQIAndUnmarshal1()  + 0x91 bytes
>  ole32.dll!CStdMarshal::Begin_QueryRemoteInterfaces()  + 0x37 bytes
>  ole32.dll!CStdMarshal::QueryRemoteInterfaces()  + 0x37 bytes
>  ole32.dll!CStdIdentity::CInternalUnk::QueryMultipleInterfaces()  + 0xce65
> bytes
>  ole32.dll!CStdIdentity::CInternalUnk::QueryInterface()  + 0x30 bytes
>  [Managed to Native Transition]
>>>>... here is my code, accessing the COM object.
>
> "Luke Zhang [MSFT]" <lukez***@online.microsoft.com> schrieb im Newsbeitrag
> news:kKU6yN9WHHA.2352@TK2MSFTNGHUB02.phx.gbl...
>> Hello,
>>
>> I am reviewing this post. I found Walter has reproduced the and want to
>> involve more resource to find a proper solution on this issue. To better
>> communicate on this issue and find a final solution, would you please let
>> us know your actual email address? To get my email, please remove
>> "online"
>> from my display email.
>>
>> Sincerely,
>>
>> Luke Zhang
>>
>> Microsoft Online Community Support
>> ==================================================
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
>> issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
>> follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>> ==================================================
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>>
>
>

AddThis Social Bookmark Button