47
47
#include " V8/v8-buffer.h"
48
48
#include " V8/v8-utils.h"
49
49
#include " V8/v8-vpack.h"
50
+ #include " V8/v8-deadline.h"
50
51
51
52
#include < velocypack/Builder.h>
52
53
#include < velocypack/Parser.h>
@@ -154,7 +155,7 @@ std::shared_ptr<fu::Connection> V8ClientConnection::createConnection() {
154
155
setCustomError (503 , msg);
155
156
return nullptr ;
156
157
}
157
-
158
+
158
159
std::lock_guard<std::recursive_mutex> guard (_lock);
159
160
_connection = newConnection;
160
161
@@ -204,11 +205,11 @@ std::shared_ptr<fu::Connection> V8ClientConnection::createConnection() {
204
205
205
206
std::shared_ptr<fu::Connection> V8ClientConnection::acquireConnection () {
206
207
std::lock_guard<std::recursive_mutex> guard (_lock);
207
-
208
+
208
209
_lastErrorMessage = " " ;
209
210
_lastHttpReturnCode = 0 ;
210
-
211
- if (!_connection ||
211
+
212
+ if (!_connection ||
212
213
(_connection->state () == fu::Connection::State::Disconnected ||
213
214
_connection->state () == fu::Connection::State::Failed)) {
214
215
return createConnection ();
@@ -455,6 +456,9 @@ static void ClientConnection_ConstructorCallback(v8::FunctionCallbackInfo<v8::Va
455
456
static void ClientConnection_reconnect (v8::FunctionCallbackInfo<v8::Value> const & args) {
456
457
TRI_V8_TRY_CATCH_BEGIN (isolate);
457
458
v8::HandleScope scope (isolate);
459
+ if (isExecutionDeadlineReached (isolate)) {
460
+ return ;
461
+ }
458
462
459
463
V8ClientConnection* v8connection =
460
464
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -564,6 +568,9 @@ static void ClientConnection_httpGetAny(v8::FunctionCallbackInfo<v8::Value> cons
564
568
TRI_V8_TRY_CATCH_BEGIN (isolate);
565
569
v8::HandleScope scope (isolate);
566
570
571
+ if (isExecutionDeadlineReached (isolate)) {
572
+ return ;
573
+ }
567
574
// get the connection
568
575
V8ClientConnection* v8connection =
569
576
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -614,6 +621,9 @@ static void ClientConnection_httpHeadAny(v8::FunctionCallbackInfo<v8::Value> con
614
621
bool raw) {
615
622
TRI_V8_TRY_CATCH_BEGIN (isolate);
616
623
v8::HandleScope scope (isolate);
624
+ if (isExecutionDeadlineReached (isolate)) {
625
+ return ;
626
+ }
617
627
618
628
// get the connection
619
629
V8ClientConnection* v8connection =
@@ -666,6 +676,9 @@ static void ClientConnection_httpDeleteAny(v8::FunctionCallbackInfo<v8::Value> c
666
676
bool raw) {
667
677
TRI_V8_TRY_CATCH_BEGIN (isolate);
668
678
v8::HandleScope scope (isolate);
679
+ if (isExecutionDeadlineReached (isolate)) {
680
+ return ;
681
+ }
669
682
670
683
// get the connection
671
684
V8ClientConnection* v8connection =
@@ -722,6 +735,9 @@ static void ClientConnection_httpOptionsAny(v8::FunctionCallbackInfo<v8::Value>
722
735
bool raw) {
723
736
TRI_V8_TRY_CATCH_BEGIN (isolate);
724
737
v8::HandleScope scope (isolate);
738
+ if (isExecutionDeadlineReached (isolate)) {
739
+ return ;
740
+ }
725
741
726
742
// get the connection
727
743
V8ClientConnection* v8connection =
@@ -774,6 +790,9 @@ static void ClientConnection_httpPostAny(v8::FunctionCallbackInfo<v8::Value> con
774
790
bool raw) {
775
791
TRI_V8_TRY_CATCH_BEGIN (isolate);
776
792
v8::HandleScope scope (isolate);
793
+ if (isExecutionDeadlineReached (isolate)) {
794
+ return ;
795
+ }
777
796
778
797
// get the connection
779
798
V8ClientConnection* v8connection =
@@ -825,6 +844,9 @@ static void ClientConnection_httpPutAny(v8::FunctionCallbackInfo<v8::Value> cons
825
844
bool raw) {
826
845
TRI_V8_TRY_CATCH_BEGIN (isolate);
827
846
v8::HandleScope scope (isolate);
847
+ if (isExecutionDeadlineReached (isolate)) {
848
+ return ;
849
+ }
828
850
829
851
// get the connection
830
852
V8ClientConnection* v8connection =
@@ -878,6 +900,9 @@ static void ClientConnection_httpPatchAny(v8::FunctionCallbackInfo<v8::Value> co
878
900
TRI_V8_TRY_CATCH_BEGIN (isolate);
879
901
v8::HandleScope scope (isolate);
880
902
903
+ if (isExecutionDeadlineReached (isolate)) {
904
+ return ;
905
+ }
881
906
// get the connection
882
907
V8ClientConnection* v8connection =
883
908
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -928,6 +953,10 @@ static void ClientConnection_httpSendFile(v8::FunctionCallbackInfo<v8::Value> co
928
953
TRI_V8_TRY_CATCH_BEGIN (isolate);
929
954
v8::HandleScope scope (isolate);
930
955
956
+ if (isExecutionDeadlineReached (isolate)) {
957
+ return ;
958
+ }
959
+
931
960
// get the connection
932
961
V8ClientConnection* v8connection =
933
962
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -982,6 +1011,9 @@ static void ClientConnection_getEndpoint(v8::FunctionCallbackInfo<v8::Value> con
982
1011
TRI_V8_TRY_CATCH_BEGIN (isolate)
983
1012
v8::HandleScope scope (isolate);
984
1013
1014
+ if (isExecutionDeadlineReached (isolate)) {
1015
+ return ;
1016
+ }
985
1017
// get the connection
986
1018
V8ClientConnection* v8connection =
987
1019
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1013,6 +1045,9 @@ static void ClientConnection_importCsv(v8::FunctionCallbackInfo<v8::Value> const
1013
1045
v8::Local<v8::Context> context = isolate->GetCurrentContext ();
1014
1046
v8::HandleScope scope (isolate);
1015
1047
1048
+ if (isExecutionDeadlineReached (isolate)) {
1049
+ return ;
1050
+ }
1016
1051
if (args.Length () < 2 ) {
1017
1052
TRI_V8_THROW_EXCEPTION_USAGE (
1018
1053
" importCsvFile(<filename>, <collection>[, <options>])" );
@@ -1121,6 +1156,9 @@ static void ClientConnection_importJson(v8::FunctionCallbackInfo<v8::Value> cons
1121
1156
TRI_V8_TRY_CATCH_BEGIN (isolate);
1122
1157
v8::HandleScope scope (isolate);
1123
1158
1159
+ if (isExecutionDeadlineReached (isolate)) {
1160
+ return ;
1161
+ }
1124
1162
if (args.Length () < 2 ) {
1125
1163
TRI_V8_THROW_EXCEPTION_USAGE (" importJsonFile(<filename>, <collection>)" );
1126
1164
}
@@ -1195,6 +1233,10 @@ static void ClientConnection_lastHttpReturnCode(v8::FunctionCallbackInfo<v8::Val
1195
1233
TRI_V8_TRY_CATCH_BEGIN (isolate);
1196
1234
v8::HandleScope scope (isolate);
1197
1235
1236
+ if (isExecutionDeadlineReached (isolate)) {
1237
+ return ;
1238
+ }
1239
+
1198
1240
// get the connection
1199
1241
V8ClientConnection* v8connection =
1200
1242
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1220,6 +1262,10 @@ static void ClientConnection_lastErrorMessage(v8::FunctionCallbackInfo<v8::Value
1220
1262
TRI_V8_TRY_CATCH_BEGIN (isolate);
1221
1263
v8::HandleScope scope (isolate);
1222
1264
1265
+ if (isExecutionDeadlineReached (isolate)) {
1266
+ return ;
1267
+ }
1268
+
1223
1269
// get the connection
1224
1270
V8ClientConnection* v8connection =
1225
1271
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1245,6 +1291,10 @@ static void ClientConnection_isConnected(v8::FunctionCallbackInfo<v8::Value> con
1245
1291
TRI_V8_TRY_CATCH_BEGIN (isolate);
1246
1292
v8::HandleScope scope (isolate);
1247
1293
1294
+ if (isExecutionDeadlineReached (isolate)) {
1295
+ return ;
1296
+ }
1297
+
1248
1298
// get the connection
1249
1299
V8ClientConnection* v8connection =
1250
1300
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1272,6 +1322,10 @@ static void ClientConnection_forceJson(v8::FunctionCallbackInfo<v8::Value> const
1272
1322
TRI_V8_TRY_CATCH_BEGIN (isolate);
1273
1323
v8::HandleScope scope (isolate);
1274
1324
1325
+ if (isExecutionDeadlineReached (isolate)) {
1326
+ return ;
1327
+ }
1328
+
1275
1329
// get the connection
1276
1330
V8ClientConnection* v8connection =
1277
1331
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1306,6 +1360,10 @@ static void ClientConnection_timeout(v8::FunctionCallbackInfo<v8::Value> const&
1306
1360
TRI_V8_TRY_CATCH_BEGIN (isolate);
1307
1361
v8::HandleScope scope (isolate);
1308
1362
1363
+ if (isExecutionDeadlineReached (isolate)) {
1364
+ return ;
1365
+ }
1366
+
1309
1367
// get the connection
1310
1368
V8ClientConnection* v8connection =
1311
1369
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1343,6 +1401,10 @@ static void ClientConnection_toString(v8::FunctionCallbackInfo<v8::Value> const&
1343
1401
TRI_V8_TRY_CATCH_BEGIN (isolate);
1344
1402
v8::HandleScope scope (isolate);
1345
1403
1404
+ if (isExecutionDeadlineReached (isolate)) {
1405
+ return ;
1406
+ }
1407
+
1346
1408
// get the connection
1347
1409
V8ClientConnection* v8connection =
1348
1410
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1379,6 +1441,10 @@ static void ClientConnection_getVersion(v8::FunctionCallbackInfo<v8::Value> cons
1379
1441
TRI_V8_TRY_CATCH_BEGIN (isolate);
1380
1442
v8::HandleScope scope (isolate);
1381
1443
1444
+ if (isExecutionDeadlineReached (isolate)) {
1445
+ return ;
1446
+ }
1447
+
1382
1448
// get the connection
1383
1449
V8ClientConnection* v8connection =
1384
1450
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1403,6 +1469,10 @@ static void ClientConnection_getMode(v8::FunctionCallbackInfo<v8::Value> const&
1403
1469
TRI_V8_TRY_CATCH_BEGIN (isolate);
1404
1470
v8::HandleScope scope (isolate);
1405
1471
1472
+ if (isExecutionDeadlineReached (isolate)) {
1473
+ return ;
1474
+ }
1475
+
1406
1476
// get the connection
1407
1477
V8ClientConnection* v8connection =
1408
1478
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1427,6 +1497,10 @@ static void ClientConnection_getRole(v8::FunctionCallbackInfo<v8::Value> const&
1427
1497
TRI_V8_TRY_CATCH_BEGIN (isolate);
1428
1498
v8::HandleScope scope (isolate);
1429
1499
1500
+ if (isExecutionDeadlineReached (isolate)) {
1501
+ return ;
1502
+ }
1503
+
1430
1504
// get the connection
1431
1505
V8ClientConnection* v8connection =
1432
1506
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1451,6 +1525,10 @@ static void ClientConnection_getDatabaseName(v8::FunctionCallbackInfo<v8::Value>
1451
1525
TRI_V8_TRY_CATCH_BEGIN (isolate);
1452
1526
v8::HandleScope scope (isolate);
1453
1527
1528
+ if (isExecutionDeadlineReached (isolate)) {
1529
+ return ;
1530
+ }
1531
+
1454
1532
// get the connection
1455
1533
V8ClientConnection* v8connection =
1456
1534
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1475,6 +1553,10 @@ static void ClientConnection_setDatabaseName(v8::FunctionCallbackInfo<v8::Value>
1475
1553
TRI_V8_TRY_CATCH_BEGIN (isolate);
1476
1554
v8::HandleScope scope (isolate);
1477
1555
1556
+ if (isExecutionDeadlineReached (isolate)) {
1557
+ return ;
1558
+ }
1559
+
1478
1560
// get the connection
1479
1561
V8ClientConnection* v8connection =
1480
1562
TRI_UnwrapClass<V8ClientConnection>(args.Holder (), WRAP_TYPE_CONNECTION, TRI_IGETC);
@@ -1590,7 +1672,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
1590
1672
} else {
1591
1673
req->header .contentType (fu::ContentType::Custom);
1592
1674
}
1593
-
1675
+
1594
1676
} else if (boost::iequals (StaticStrings::Accept, pair.first )) {
1595
1677
if (pair.second == StaticStrings::MimeTypeVPack) {
1596
1678
req->header .acceptType (fu::ContentType::VPack);
@@ -1667,7 +1749,9 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
1667
1749
req->header .acceptType (fu::ContentType::VPack);
1668
1750
}
1669
1751
}
1670
- req->timeout (std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1752
+ req->timeout (
1753
+ correctTimeoutToExecutionDeadline (
1754
+ std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));
1671
1755
1672
1756
std::shared_ptr<fu::Connection> connection = acquireConnection ();
1673
1757
if (!connection || connection->state () == fu::Connection::State::Failed) {
@@ -1683,7 +1767,7 @@ v8::Local<v8::Value> V8ClientConnection::requestData(
1683
1767
} catch (fu::Error const & ec) {
1684
1768
rc = ec;
1685
1769
}
1686
-
1770
+
1687
1771
if (rc == fu::Error::ConnectionClosed && retry) {
1688
1772
retry = false ;
1689
1773
goto again;
@@ -1696,7 +1780,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
1696
1780
v8::Isolate* isolate, fu::RestVerb method, arangodb::velocypack::StringRef const & location,
1697
1781
v8::Local<v8::Value> const & body,
1698
1782
std::unordered_map<std::string, std::string> const & headerFields) {
1699
-
1783
+
1700
1784
bool retry = true ;
1701
1785
1702
1786
again:
@@ -1749,7 +1833,9 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
1749
1833
if (req->header .acceptType () == fu::ContentType::Unset) {
1750
1834
req->header .acceptType (fu::ContentType::VPack);
1751
1835
}
1752
- req->timeout (std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout));
1836
+ req->timeout (
1837
+ correctTimeoutToExecutionDeadline (
1838
+ std::chrono::duration_cast<std::chrono::milliseconds>(_requestTimeout)));
1753
1839
1754
1840
std::shared_ptr<fu::Connection> connection = acquireConnection ();
1755
1841
if (!connection || connection->state () == fu::Connection::State::Failed) {
@@ -1766,7 +1852,7 @@ v8::Local<v8::Value> V8ClientConnection::requestDataRaw(
1766
1852
_lastErrorMessage.assign (fu::to_string (e));
1767
1853
_lastHttpReturnCode = 503 ;
1768
1854
}
1769
-
1855
+
1770
1856
if (rc == fu::Error::ConnectionClosed && retry) {
1771
1857
retry = false ;
1772
1858
goto again;
@@ -1939,7 +2025,7 @@ v8::Local<v8::Value> V8ClientConnection::handleResult(v8::Isolate* isolate,
1939
2025
VPackParser parser (builder);
1940
2026
try {
1941
2027
parser.parse (str, sb.size ());
1942
- ret = TRI_VPackToV8 (isolate, builder->slice (), parser.options , nullptr );
2028
+ ret = TRI_VPackToV8 (isolate, builder->slice (), parser.options , nullptr );
1943
2029
} catch (std::exception const & ex) {
1944
2030
std::string err (" Error parsing the server JSON reply: " );
1945
2031
err += ex.what ();
0 commit comments