8000 Fix Cluster shutdown handling of http connections (#7809) · HighAvailabilityLab/arangodb@c309479 · GitHub
[go: up one dir, main page]

Skip to content

Commit c309479

Browse files
dothebartjsteemann
authored andcommitted
Fix Cluster shutdown handling of http connections (arangodb#7809)
1 parent 33b288e commit c309479

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

lib/SimpleHttpClient/ClientConnection.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ bool ClientConnection::writeClientConnection(void const* buffer, size_t length,
132132
return false;
133133
}
134134

135+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
136+
_written += (uint64_t)status;
137+
#endif
135138
*bytesWritten = (size_t)status;
136139

137140
return true;
@@ -174,7 +177,9 @@ bool ClientConnection::readClientConnection(StringBuffer& stringBuffer,
174177
disconnect();
175178
return true;
176179
}
177-
180+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
181+
_read += (uint64_t)lenRead;
182+
#endif
178183
stringBuffer.increaseLength(lenRead);
179184
} while (readable());
180185

lib/SimpleHttpClient/GeneralClientConnection.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323

2424
#include "GeneralClientConnection.h"
2525
#include "ApplicationFeatures/ApplicationServer.h"
26+
#include "ApplicationFeatures/CommunicationPhase.h"
2627
#include "SimpleHttpClient/ClientConnection.h"
2728
#include "SimpleHttpClient/SslClientConnection.h"
29+
#include "Logger/Logger.h"
2830
#include "Basics/socket-utils.h"
2931

3032
#ifdef TRI_HAVE_POLL_H
@@ -67,6 +69,10 @@ GeneralClientConnection::GeneralClientConnection(Endpoint* endpoint,
6769
_connectRetries(connectRetries),
6870
_numConnectRetries(0),
6971
_isConnected(false),
72+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
73+
_read(0),
74+
_written(0),
75+
#endif
7076
_isInterrupted(false) {
7177
TRI_invalidatesocket(&_socket);
7278
}
@@ -81,6 +87,10 @@ GeneralClientConnection::GeneralClientConnection(
8187
_connectRetries(connectRetries),
8288
_numConnectRetries(0),
8389
_isConnected(false),
90+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
91+
_read(0),
92+
_written(0),
93+
#endif
8494
_isInterrupted(false) {
8595
TRI_invalidatesocket(&_socket);
8696
}
@@ -157,6 +167,16 @@ bool GeneralClientConnection::connect() {
157167

158168
void GeneralClientConnection::disconnect() {
159169
if (isConnected()) {
170+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
171+
if ((_written + _read) == 0) {
172+
std::string bt;
173+
TRI_GetBacktrace(bt);
174+
LOG_TOPIC(WARN, Logger::COMMUNICATION) <<
175+
"Closing HTTP-connection right after opening it without sending data!" << bt;
176+
}
177+
_written = 0;
178+
_read = 0;
179+
#endif
160180
disconnectSocket();
161181
_numConnectRetries = 0;
162182
_isConnected = false;
@@ -176,6 +196,9 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
176196
double start = TRI_microtime();
177197
int res;
178198

199+
auto comm = application_features::ApplicationServer::getFeature<
200+
arangodb::application_features::CommunicationFeaturePhase>("CommunicationPhase");
201+
179202
#ifdef TRI_HAVE_POLL_H
180203
// Here we have poll, on all other platforms we use select
181204
double sinceLastSocketCheck = start;
@@ -212,7 +235,7 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
212235
}
213236

214237
if (res == 0) {
215-
if (isInterrupted() || application_features::ApplicationServer::isStopping()) {
238+
if (isInterrupted() || !comm->getCommAllowed()) {
216239
_errorDetails = std::string("command locally aborted");
217240
TRI_set_errno(TRI_ERROR_REQUEST_CANCELED);
218241
return false;
@@ -294,7 +317,7 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
294317
timeout = timeout - (end - start);
295318
start = end;
296319
} else if (res == 0) {
297-
if (isInterrupted() || application_features::ApplicationServer::isStopping()) {
320+
if (isInterrupted() || !comm->getCommAllowed()) {
298321
_errorDetails = std::string("command locally aborted");
299322
TRI_set_errno(TRI_ERROR_REQUEST_CANCELED);
300323
return false;
@@ -311,7 +334,7 @@ bool GeneralClientConnection::prepare(TRI_socket_t socket, double timeout, bool
311334
#endif
312335

313336
if (res > 0) {
314-
if (isInterrupted() || application_features::ApplicationServer::isStopping()) {
337+
if (isInterrupted() || !comm->getCommAllowed()) {
315338
_errorDetails = std::string("command locally aborted");
316339
TRI_set_errno(TRI_ERROR_REQUEST_CANCELED);
317340
return false;

lib/SimpleHttpClient/GeneralClientConnection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ class GeneralClientConnection {
247247

248248
bool _isConnected;
249249

250+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
251+
uint64_t _read;
252+
uint64_t _written;
253+
#endif
254+
250255
//////////////////////////////////////////////////////////////////////////////
251256
/// @brief whether or not the current operation should be interrupted
252257
//////////////////////////////////////////////////////////////////////////////

lib/SimpleHttpClient/SslClientConnection.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,18 @@ bool SslClientConnection::connectSocket() {
334334
(errorDetail == SSL_ERROR_WANT_WRITE)) {
335335
return true;
336336
}
337-
337+
338338
/* Gets the earliest error code from the
339339
thread's error queue and removes the entry. */
340340
unsigned long lastError = ERR_get_error();
341-
341+
342342
if (errorDetail == SSL_ERROR_SYSCALL && lastError == 0) {
343343
if (ret == 0) {
344344
_errorDetails += "an EOF was observed that violates the protocol. this may happen when the other side has closed the connection";
345345
} else if (ret == -1) {
346346
_errorDetails += "I/O reported by BIO";
347347
}
348-
}
348+
}
349349

350350
switch (errorDetail) {
351351
case 0x1407E086:
@@ -376,16 +376,16 @@ bool SslClientConnection::connectSocket() {
376376
_errorDetails += std::string(" - details: ") + errorBuffer;
377377
break;
378378
}
379-
379+
380380
disconnectSocket();
381381
_isConnected = false;
382382
return false;
383383
}
384384

385-
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "SSL connection opened: "
386-
<< SSL_get_cipher(_ssl) << ", "
387-
<< SSL_get_cipher_version(_ssl)
388-
<< " (" << SSL_get_cipher_bits(_ssl, nullptr) << " bits)";
385+
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "SSL connection opened: "
386+
<< SSL_get_cipher(_ssl) << ", "
387+
<< SSL_get_cipher_version(_ssl)
388+
<< " (" << SSL_get_cipher_bits(_ssl, nullptr) << " bits)";
389389

390390
return true;
391391
}
@@ -427,7 +427,9 @@ bool SslClientConnection::writeClientConnection(void const* buffer,
427427
switch (err) {
428428
case SSL_ERROR_NONE:
429429
*bytesWritten = written;
430-
430+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
431+
_written += written;
432+
#endif
431433
return true;
432434

433435
case SSL_ERROR_ZERO_RETURN:
@@ -456,7 +458,7 @@ bool SslClientConnection::writeClientConnection(void const* buffer,
456458
_errorDetails = std::string("SSL: while writing: ") + errorBuffer;
457459
break;
458460
}
459-
461+
460462
default:
461463
/* a true error */
462464
_errorDetails =
@@ -502,6 +504,9 @@ bool SslClientConnection::readClientConnection(StringBuffer& stringBuffer,
502504
switch (SSL_get_error(_ssl, lenRead)) {
503505
case SSL_ERROR_NONE:
504506
stringBuffer.increaseLength(lenRead);
507+
#ifdef ARANGODB_ENABLE_MAINTAINER_MODE
508+
_read += lenRead;
509+
#endif
505510
break;
506511

507512
case SSL_ERROR_ZERO_RETURN:

0 commit comments

Comments
 (0)
0