8000 Let the `arangosh` reconnect automatically. (#10002) · distrubuted/arangodb@b5aca27 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5aca27

Browse files
neunhoefjsteemann
authored andcommitted
Let the arangosh reconnect automatically. (arangodb#10002)
1 parent 98c3b5c commit b5aca27

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

arangosh/Shell/V8ClientConnection.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ std::shared_ptr<fuerte::Connection> V8ClientConnection::createConnection() {
163163
return nullptr;
164164
}
165165

166+
std::shared_ptr<fuerte::Connection> V8ClientConnection::acquireConnection() {
167+
std::lock_guard<std::recursive_mutex> guard(_lock);
168+
169+
_lastErrorMessage = "";
170+
_lastHttpReturnCode = 0;
171+
172+
if (!_connection || _connection->state() == fuerte::Connection::State::Failed) {
173+
return createConnection();
174+
}
175+
return _connection;
176+
}
177+
166178
void V8ClientConnection::setInterrupted(bool interrupted) {
167179
std::lock_guard<std::recursive_mutex> guard(_lock);
168180
if (interrupted && _connection != nullptr) {
@@ -1499,14 +1511,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
14991511
}
15001512
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
15011513

1502-
std::shared_ptr<fuerte::Connection> connection;
1503-
{
1504-
std::lock_guard<std::recursive_mutex> guard(_lock);
1505-
_lastErrorMessage = "";
1506-
_lastHttpReturnCode = 0;
1507-
connection = _connection;
1508-
}
1509-
1514+
std::shared_ptr<fuerte::Connection> connection = acquireConnection();
15101515
if (!connection || connection->state() == fuerte::Connection::State::Failed) {
15111516
TRI_V8_SET_EXCEPTION_MESSAGE(TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT,
15121517
"not connected");
@@ -1527,8 +1532,6 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
15271532
v8::Isolate* isolate, fuerte::RestVerb method, arangodb::velocypack::StringRef const& location,
15281533
v8::Local<v8::Value> const& body,
15291534
std::unordered_map<std::string, std::string> const& headerFields) {
1530-
_lastErrorMessage = "";
1531-
_lastHttpReturnCode = 0;
15321535

15331536
auto req = std::make_unique<fuerte::Request>();
15341537
req->header.restVerb = method;
@@ -1565,13 +1568,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
15651568
}
15661569
req->timeout(std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
15671570

1568-
std::shared_ptr<fuerte::Connection> connection;
1569-
{
1570-
std::lock_guard<std::recursive_mutex> guard(_lock);
1571-
_lastErrorMessage = "";
1572-
_lastHttpReturnCode = 0;
1573-
connection = _connection;
1574-
}
1571+
std::shared_ptr<fuerte::Connection> connection = acquireConnection();
15751572

15761573
if (!connection || connection->state() == fuerte::Connection::State::Failed) {
15771574
TRI_V8_SET_EXCEPTION_MESSAGE(TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT,

arangosh/Shell/V8ClientConnection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class V8ClientConnection {
118118

119119
private:
120120
std::shared_ptr<fuerte::Connection> createConnection();
121+
std::shared_ptr<fuerte::Connection> acquireConnection();
121122

122123
v8::Local<v8::Value> requestData(v8::Isolate* isolate, fuerte::RestVerb verb,
123124
arangodb::velocypack::StringRef const& location,

0 commit comments

Comments
 (0)
0