Long lived bidirectional stream closed after laptop goes to sleep

148 views
Skip to first unread message

IIFE

unread,
Oct 18, 2021, 7:38:38 AM10/18/21
to grpc.io
Hi,

I've got a sync C++ client that opens a long lived bidirectional stream to a sync C++ server. I'm seeing an issue where if I keep my client open and then put my machine to sleep, the connection is terminated a number of hours. Here are the logs I got.

I connected the client at 00:25, and then got the following log:
18/10/2021 03:07:48.578
File: src\core\ext\transport\chttp2\transport\chttp2_transport.cc
Line: 2871
Message: ipv4:127.0.0.1:51656: Keepalive watchdog fired. Closing transport.

Then at the time I woke up my machine from sleep mode, I saw the following log:
18/10/2021 09:22:15.372
src\core\lib\security\transport\security_handshaker.cc
Line: 183
Message: Security handshake failed: {"created":"@1634545335.372000000","description":"Handshake read failed","file":"src\17cc203898-db2679e7f2.clean\src\core\lib\security\transport\security_handshaker.cc","file_line":425,"referenced_errors":[{"created":"@1634545335.372000000","description":"TCP stream shutting down","file":"src\17cc203898-db2679e7f2.clean\src\core\lib\iomgr\tcp_windows.cc","file_line":228,"referenced_errors":[{"created":"@1634545334.503000000","description":"Handshake timed out","file":"src\17cc203898-db2679e7f2.clean\src\core\lib\channel\handshaker.cc","file_line":163}]}]}

I haven't set GRPC_ARG_KEEPALIVE_TIME_MS on the client channel, which according to the documentation is disabled by default. Do I need to configure keepalive settings on the client to resolve this issue, or is there something else going on?

Thanks

Piotr Morgwai Kotarbinski

unread,
Oct 19, 2021, 2:19:27 AM10/19/21
to grpc.io
I believe it's an expected behavior: your laptop cannot correctly reply to any messages or HTTP/2 control frames while sleeping, so terminating a call seems like a quite reasonable thing to do.
I don't know low level details of HTTP/2 stream control, though, so hopefully someone with a better knowledge in this area can give a better answer.
Furthermore, it may depend on TCP socket options: if the other side performs TCP keep-alive checks and notices that your laptop is gone, then it will terminate the connection.

Cheers!

IIFE

unread,
Oct 19, 2021, 5:11:39 AM10/19/21
to grpc.io
Would disabling the keepalive option on the server side not resolve the issue? If the server is sending a keepalive, which the client is not replying to, causing the server to close the transport, then it seems disabling keepalive on the server (which is enabled by default every 2 hours) can resolve the issue. Is there a timeout on long-lived streams? Because if there isn't, and I can just keep the stream open, then I don't need keepalive to be enabled on the server.

In my situation above the server and client are both on the same machine that is being put to sleep (the server is just a Windows service). So the "other side" is just the same laptop.

Thanks.
Reply all
Reply to author
Forward
0 new messages