@@ -163,6 +163,18 @@ std::shared_ptr<fuerte::Connection> V8ClientConnection::createConnection() {
163
163
return nullptr ;
164
164
}
165
165
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
+
166
178
void V8ClientConnection::setInterrupted (bool interrupted) {
167
179
std::lock_guard<std::recursive_mutex> guard (_lock);
168
180
if (interrupted && _connection != nullptr ) {
@@ -1499,14 +1511,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
1499
1511
}
1500
1512
req->timeout (std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1501
1513
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 ();
1510
1515
if (!connection || connection->state () == fuerte::Connection::State::Failed) {
1511
1516
TRI_V8_SET_EXCEPTION_MESSAGE (TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT,
1512
1517
" not connected" );
@@ -1527,8 +1532,6 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
1527
1532
v8::Isolate* isolate, fuerte::RestVerb method, arangodb::velocypack::StringRef const & location,
1528
1533
v8::Local<v8::Value> const & body,
1529
1534
std::unordered_map<std::string, std::string> const & headerFields) {
1530
- _lastErrorMessage = " " ;
1531
- _lastHttpReturnCode = 0 ;
1532
1535
1533
1536
auto req = std::make_unique<fuerte::Request>();
1534
1537
req->header .restVerb = method;
@@ -1565,13 +1568,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
1565
1568
}
1566
1569
req->timeout (std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1567
1570
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 ();
1575
1572
1576
1573
if (!connection || connection->state () == fuerte::Connection::State::Failed) {
1577
1574
TRI_V8_SET_EXCEPTION_MESSAGE (TRI_ERROR_SIMPLE_CLIENT_COULD_NOT_CONNECT,
0 commit comments