8000 Fixed false http error codes in timeout case. Also reactivated retry … · Sandychuang/arangodb@411dc7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 411dc7e

Browse files
mchackijsteemann
authored andcommitted
Fixed false http error codes in timeout case. Also reactivated retry in error case. (arangodb#4760)
1 parent 4ff33c0 commit 411dc7e

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

js/common/bootstrap/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"ERROR_HTTP_PRECONDITION_FAILED" : { "code" : 412, "message" : "precondition failed" },
5050
"ERROR_HTTP_SERVER_ERROR" : { "code" : 500, "message" : "internal server error" },
5151
"ERROR_HTTP_SERVICE_UNAVAILABLE" : { "code" : 503, "message" : "service unavailable" },
52+
"ERROR_HTTP_GATEWAY_TIMEOUT" : { "code" : 504, "message" : "gateway timeout" },
5253
"ERROR_HTTP_CORRUPTED_JSON" : { "code" : 600, "message" : "invalid JSON object" },
5354
"ERROR_HTTP_SUPERFLUOUS_SUFFICES" : { "code" : 601, "message" : "superfluous URL suffices" },
5455
"ERROR_ARANGO_ILLEGAL_STATE" : { "code" : 1000, "message" : "illegal state" },

lib/Basics/errors.dat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ERROR_HTTP_NOT_ACCEPTABLE,406,"request not acceptable","Will be raised when an u
4646
ERROR_HTTP_PRECONDITION_FAILED,412,"precondition failed","Will be raised when a precondition for an HTTP request is not met."
4747
ERROR_HTTP_SERVER_ERROR,500,"internal server error","Will be raised when an internal server is encountered."
4848
ERROR_HTTP_SERVICE_UNAVAILABLE,503,"service unavailable","Will be raised when a service is temporarily unavailable."
49+
ERROR_HTTP_GATEWAY_TIMEOUT,504,"gateway timeout","Will be raised when a service contacted by ArangoDB does not respond in a timely manner."
4950

5051
################################################################################
5152
## HTTP processing errors

lib/Basics/voc-errors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void TRI_InitializeErrorMessages () {
4545
REG_ERROR(ERROR_HTTP_PRECONDITION_FAILED, "precondition failed");
4646
REG_ERROR(ERROR_HTTP_SERVER_ERROR, "internal server error");
4747
REG_ERROR(ERROR_HTTP_SERVICE_UNAVAILABLE, "service unavailable");
48+
REG_ERROR(ERROR_HTTP_GATEWAY_TIMEOUT, "gateway timeout");
4849
REG_ERROR(ERROR_HTTP_CORRUPTED_JSON, "invalid JSON object");
4950
REG_ERROR(ERROR_HTTP_SUPERFLUOUS_SUFFICES, "superfluous URL suffices");
5051
REG_ERROR(ERROR_ARANGO_ILLEGAL_STATE, "illegal state");

lib/Basics/voc-errors.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
/// Will be raised when an internal server is encountered.
9191
/// - 503: @LIT{service unavailable}
9292
/// Will be raised when a service is temporarily unavailable.
93+
/// - 504: @LIT{gateway timeout}
94+
/// Will be raised when a service contacted by ArangoDB does not respond in a
95+
/// timely manner.
9396
/// - 600: @LIT{invalid JSON object}
9497
/// Will be raised when a string representation of a JSON object is corrupt.
9598
/// - 601: @LIT{superfluous URL suffices}
@@ -1172,6 +1175,17 @@ void TRI_InitializeErrorMessages ();
11721175

11731176
#define TRI_ERROR_HTTP_SERVICE_UNAVAILABLE (503)
11741177

1178+
////////////////////////////////////////////////////////////////////////////////
1179+
/// @brief 504: ERROR_HTTP_GATEWAY_TIMEOUT
1180+
///
1181+
/// gateway timeout
1182+
///
1183+
/// Will be raised when a service contacted by ArangoDB does not respond in a
1184+
/// timely manner.
1185+
////////////////////////////////////////////////////////////////////////////////
1186+
1187+
#define TRI_ERROR_HTTP_GATEWAY_TIMEOUT (504)
1188+
11751189
////////////////////////////////////////////////////////////////////////////////
11761190
/// @brief 600: ERROR_HTTP_CORRUPTED_JSON
11771191
///

lib/SimpleHttpClient/SimpleHttpClient.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ SimpleHttpResult* SimpleHttpClient::doRequest(
318318
return nullptr;
319319
}
320320
this->close(); // this sets the state to IN_CONNECT for a retry
321-
_state = DEAD;
322-
setErrorMessage("Request timeout reached");
321+
LOG_TOPIC(DEBUG, arangodb::Logger::HTTPCLIENT) << _errorMessage;
322+
usleep(5000);
323323
break;
324324
}
325325

@@ -340,15 +340,15 @@ SimpleHttpResult* SimpleHttpClient::doRequest(
340340
processHeader();
341341
}
342342

343-
if (_state == IN_READ_BODY && !_result->hasContentLength()) {
344-
// If we are reading the body and no content length was
345-
// found in the header, then we must read until no more
346-
// progress is made (but without an error), this then means
347-
// that the server has closed the connection and we must
348-
// process the body one more time:
349-
_result->setContentLength(_readBuffer.length() - _readBufferOffset);
350-
processBody();
351-
} else if (_state == IN_READ_BODY) {
343+
if (_state == IN_READ_BODY) {
344+
if (!_result->hasContentLength()) {
345+
// If we are reading the body and no content length was
346+
// found in the header, then we must read until no more
347+
// progress is made (but without an error), this then means
348+
// that the server has closed the connection and we must
349+
// process the body one more time:
350+
_result->setContentLength(_readBuffer.length() - _readBufferOffset);
351+
}
352352
processBody();
353353
}
354354

@@ -400,6 +400,7 @@ SimpleHttpResult* SimpleHttpClient::doRequest(
400400

401401
if (_state < FINISHED && _errorMessage.empty()) {
402402
setErrorMessage("Request timeout reached");
403+
_result->setHttpReturnCode(TRI_ERROR_HTTP_GATEWAY_TIMEOUT);
403404
}
404405

405406
// set result type in getResult()

lib/V8/v8-utils.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void JS_Download(v8::FunctionCallbackInfo<v8::Value> const& args) {
885885
body.size(), headerFields));
886886

887887
int returnCode = 500; // set a default
888-
std::string returnMessage;
888+
std::string returnMessage = "";
889889

890890
if (response == nullptr || !response->isComplete()) {
891891
// save error message
@@ -919,11 +919,6 @@ void JS_Download(v8::FunctionCallbackInfo<v8::Value> const& args) {
919919
continue;
920920
}
921921

922-
result->Set(TRI_V8_ASCII_STRING(isolate, "code"),
923-
v8::Number::New(isolate, returnCode));
924-
result->Set(TRI_V8_ASCII_STRING(isolate, "message"),
925-
TRI_V8_STD_STRING(isolate, returnMessage));
926-
927922
// process response headers
928923
auto const& responseHeaders = response->getHeaderFields();
929924

0 commit comments

Comments
 (0)
0