MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / tryToReconnect

Method tryToReconnect

programs/client/FuzzLoop.cpp:58–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58bool Client::tryToReconnect(const uint32_t max_reconnection_attempts, const uint32_t time_to_sleep_between_reconnects)
59{
60 chassert(max_reconnection_attempts);
61 if (!connection->isConnected())
62 {
63 // Try to reconnect after errors, for two reasons:
64 // 1. We might not have realized that the server died, e.g. if
65 // it sent us a <Fatal> trace and closed connection properly.
66 // 2. The connection might have gotten into a wrong state and
67 // the next query will get false positive about
68 // "Unknown packet from server".
69 for (uint32_t i = 0; i < max_reconnection_attempts; i++)
70 {
71 try
72 {
73 connection->forceConnected(connection_parameters.timeouts);
74 break;
75 }
76 catch (...)
77 {
78 // Just report it, we'll terminate below.
79 fmt::print(stderr, "Error while reconnecting to the server: {}\n", getCurrentExceptionMessage(true));
80
81 // The reconnection might fail, but we'll still be connected
82 // in the sense of `connection->isConnected() = true`,
83 // in case when the requested database doesn't exist.
84 // Disconnect manually now, so that the following code doesn't
85 // have any doubts, and the connection state is predictable.
86 connection->disconnect();
87 if (i < max_reconnection_attempts - 1)
88 {
89 std::this_thread::sleep_for(std::chrono::milliseconds(time_to_sleep_between_reconnects));
90 }
91 }
92 }
93 }
94
95 if (!connection->isConnected())
96 {
97 // Probably the server is dead because we found an assertion
98 // failure. Fail fast.
99 fmt::print(stderr, "Lost connection to the server.\n");
100
101 // Print the changed settings because they might be needed to
102 // reproduce the error.
103 printChangedSettings();
104
105 return false;
106 }
107 return true;
108}
109
110bool Client::processASTFuzzerStep(const String & query_to_execute, const ASTPtr & parsed_query)
111{

Callers

nothing calls this directly

Calls 6

sleep_forFunction · 0.85
printFunction · 0.50
isConnectedMethod · 0.45
forceConnectedMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected