@@ -57,22 +57,42 @@ void RemoteQueryExecutorReadContext::Task::run(AsyncCallback async_callback, Sus
5757 if (read_context.executor .needToSkipUnavailableShard ())
5858 return ;
5959
60- while ( true )
60+ try
6161 {
62- read_context.has_read_packet_part = PacketPart::None;
62+ while (true )
63+ {
64+ read_context.has_read_packet_part = PacketPart::None;
65+
66+ if (read_context.read_packet_type_separately )
67+ {
68+ read_context.packet .type = read_context.executor .getConnections ().receivePacketTypeUnlocked (async_callback);
69+ read_context.has_read_packet_part = PacketPart::Type;
70+ suspend_callback ();
71+ }
72+ read_context.packet = read_context.executor .getConnections ().receivePacketUnlocked (async_callback);
73+ read_context.has_read_packet_part = PacketPart::Body;
74+ if (read_context.packet .type == Protocol::Server::Data)
75+ read_context.has_data_packets = true ;
6376
64- if (read_context.read_packet_type_separately )
77+ suspend_callback ();
78+ }
79+ }
80+ catch (const Exception & e)
81+ {
82+ // / If cluster node unxepectedly shutted down (kill/segfault/power off/etc.) socket just closes.
83+ // / If initiator did not process any data packets before, this fact can be ignored.
84+ // / Unprocessed tasks will be executed on other nodes.
85+ if (e.code () == ErrorCodes::ATTEMPT_TO_READ_AFTER_EOF
86+ && !read_context.has_data_packets .load ()
87+ && read_context.executor .skipUnavailableShards ())
6588 {
66- read_context.packet .type = read_context.executor .getConnections ().receivePacketTypeUnlocked (async_callback);
67- read_context.has_read_packet_part = PacketPart::Type;
89+ read_context.packet .type = Protocol::Server::ConnectionLost;
90+ read_context.packet .exception = std::make_unique<Exception>(getCurrentExceptionMessageAndPattern (true ), getCurrentExceptionCode ());
91+ read_context.has_read_packet_part = PacketPart::Body;
6892 suspend_callback ();
6993 }
70- read_context.packet = read_context.executor .getConnections ().receivePacketUnlocked (async_callback);
71- read_context.has_read_packet_part = PacketPart::Body;
72- if (read_context.packet .type == Protocol::Server::Data)
73- read_context.has_data_packets = true ;
74-
75- suspend_callback ();
94+ else
95+ throw ;
7696 }
7797}
7898
0 commit comments