What if disconnecting a sync IPC connection while the caller is waiting.

298 views
Skip to first unread message

Lingqi Chi

unread,
Sep 13, 2021, 5:41:01 AM9/13/21
to chromi...@chromium.org, Hiroki Nakagawa, Lingqi Chi
Hi Mojo-dev,

I am adding some code which may drop the receiver end of a sync IPC pipe in the browser process, and would like to confirm the change would not hang the corresponding renderer process forever. 
More specifically, my question would be: 
What happens when the underlying mojo connection is closed while the renderer process is waiting for the response of the sync IPC over the connection? Will Mojo attempt to reconnect? Will the calling thread stop waiting for the response?

(I read this document, and found it says "What happens on the calling thread while waiting for the response of a sync method call? It continues to process incoming sync request messages (i.e., sync method calls); block other messages, including async messages and sync response messages that don’t match the ongoing sync call.". May I assume that Mojo has some mechanisms that can safely handle sync IPC in the disconnection case?

Thanks & Regards
Lingqi

Lingqi Chi

unread,
Sep 13, 2021, 5:42:26 AM9/13/21
to Lingqi Chi, chromi...@chromium.org, Hiroki Nakagawa, chrome-prerendering

Daniel Cheng

unread,
Sep 13, 2021, 5:48:15 AM9/13/21
to Lingqi Chi, Lingqi Chi, chromi...@chromium.org, Hiroki Nakagawa, chrome-prerendering
Disconnecting the message pipe will cancel the sync IPC, so the caller will not hang forever. When a Mojo method is marked [Sync], we generate an additional overload for callers that want sync behavior: https://source.chromium.org/chromium/_/chromium/chromium/src/out/+/0fdddcf89ef7ecb359851bba1fe9158cd6dc1c05:win-Debug/gen/url/mojom/url_test.mojom.h;l=88;drc=ac9e374f090ae5fc0debcff1fcf2246d1221a082

If the message pipe is closed and no reply to the sync message has been received, the sync overload will return false.

Daniel

--
You received this message because you are subscribed to the Google Groups "chromium-mojo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-moj...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-mojo/CAAfa4yxhqG3bttne1xjLzMuwGWqguz%3DYkfkYBvOB8gW7aRDwGQ%40mail.gmail.com.

Lingqi Chi

unread,
Sep 13, 2021, 8:10:04 AM9/13/21
to Daniel Cheng, Lingqi Chi, chromi...@chromium.org, Hiroki Nakagawa, chrome-prerendering
Thank you, Deniel! 
Your answer helps me a lot!~ Now I can move forward feeling safely :D! 
(I do not exactly understand the underlying logic of this mechanism. Based on the code path you give, I'm guessing InterfaceEndpointClient::SendMessageWithResponder is responsible for coping with the disconnection case, and believe this case is well handled. )

Thanks & Regards
Lingqi

Hiroki Nakagawa

unread,
Sep 13, 2021, 9:04:54 AM9/13/21
to Lingqi Chi, Daniel Cheng, chromi...@chromium.org, Chromium Loading Performance
Thank you for starting the thread & answering the question! This information is really helpful.

Background: We wanted to know this behavior as the mojo capability control needs to cancel some sync IPCs if the sender page is being prerendered :)
Reply all
Reply to author
Forward
0 new messages