{"id":107836,"date":"2023-02-16T07:00:00","date_gmt":"2023-02-16T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=107836"},"modified":"2023-02-15T21:05:13","modified_gmt":"2023-02-16T05:05:13","slug":"20230216-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230216-00\/?p=107836","title":{"rendered":"What does it mean when my cross-thread COM call fails with <CODE>RPC_<WBR>E_<WBR>SYS_<WBR>CALL_<WBR>FAILED<\/CODE>?"},"content":{"rendered":"<p>COM generates the error <code>RPC_<wbr \/>E_<wbr \/>SYS_<wbr \/>CALL_<wbr \/>FAILED<\/code> under a few circumstances.<\/p>\n<p>The first category is &#8220;a system call failed because something got corrupted&#8221;. These code paths are used if the calling thread is an MTA.<\/p>\n<ul>\n<li><code>Wait\u00adFor\u00adSingle\u00adObject<\/code> failed.<\/li>\n<li><code>Duplicate\u00adHandle<\/code> failed.<\/li>\n<\/ul>\n<p>If these calls fail, it means that the handle is invalid. The reason might be that COM&#8217;s internal bookkeeping is corrupted. Or it could be that the handle was once valid but no longer is: Maybe somebody else in the process closed COM&#8217;s handle by mistake, perhaps due to a handle double-close bug or an uninitialized variable. Or maybe the handle was closed by an outside force, perhaps the result of an inadvised attempt to <a href=\"http:\/\/technet.microsoft.com\/en-us\/magazine\/2009.04.windowsconfidential.aspx\"> force-close a handle<\/a>.<\/p>\n<p>Generally, if something is corrupted, things are already in a bad state, and you may as well just fail fast rather than try to muddle through and possibly corrupt things even worse.<\/p>\n<p>Another category is &#8220;a system call failed because we couldn&#8217;t contact the recipient.&#8221; If the destination thread is a single-threaded apartment, the request to do work is performed by posting a message to the thread, but if the thread has stopped processing messages, it&#8217;s possible that the thread&#8217;s posted message queue is full and won&#8217;t accept any new messages. In that case, the failed system call is <code>Post\u00adMessage<\/code>.<\/p>\n<p>To diagnose this problem in the case of a single-threaded apartment, check the thread that is the destination of the cross-thread COM call and ensure that it is pumping messages. It&#8217;s possible that it got stuck on a mutex or blocked on a <code>Wait\u00adFor\u00adSingle\u00adObject<\/code> that is not completing. That would prevent the thread from pumping messages, and if it stays in that state for a long time, its inbound message queue can fill up, preventing new work from being posted, and resulting in the <code>RPC_<wbr \/>E_<wbr \/>SYS_<wbr \/>CALL_<wbr \/>FAILED<\/code> error.<\/p>\n<p>Just some things to look for when you&#8217;re trying to diagnose a <code>RPC_<wbr \/>E_<wbr \/>SYS_<wbr \/>CALL_<wbr \/>FAILED<\/code> failure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Look for an unresponsive recipient.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-107836","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Look for an unresponsive recipient.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=107836"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/107836\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=107836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=107836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=107836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}