Skip to content

Commit

Permalink
Enforce a max connection timeout
Browse files Browse the repository at this point in the history
Summary:
Enforce a maximum connection timeout without impacting pooled
operations.

This allows pooled conns to set the connect timeout and
influence how long to remain queued for available conns,
while not choking up the thread with connects that are
unlikely to succeed.

Add a GFLAG as a backdoor for those who insist on doing it
the wrong way

Reviewed By: jupyung

Differential Revision: D45589828

fbshipit-source-id: 3d4642daa530848ea8ff75d822b8b7b6251a195b
  • Loading branch information
Aaron Balsara authored and facebook-github-bot committed May 8, 2023
1 parent d2db4f9 commit ded3774
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions squangle/mysql_client/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ DEFINE_int64(
10 * 1000 * 1000,
"default timeout, in micros, for mysql operations");

DEFINE_int64(
async_mysql_max_connect_timeout_micros,
#if defined(FOLLY_SANITIZE_ADDRESS) || (FOLLY_SANITIZE_THREAD)
30 * 1000 * 1000,
#else
3 * 1000 * 1000,
#endif
"The maximum connect timeout, to protect customers from themselves");

namespace facebook {
namespace common {
namespace mysql_client {
Expand Down Expand Up @@ -218,6 +227,10 @@ Operation* Operation::run() {
state() == OperationState::Unstarted, db::OperationStateException);
state_ = OperationState::Pending;
}
if (getOperationType() == db::OperationType::Connect) {
timeout_ = std::min(
Duration(FLAGS_async_mysql_max_connect_timeout_micros), timeout_);
}
return specializedRun();
}

Expand Down
1 change: 1 addition & 0 deletions squangle/mysql_client/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "squangle/mysql_client/Query.h"
#include "squangle/mysql_client/Row.h"

DECLARE_int64(async_mysql_max_connect_timeout_micros);
namespace facebook {
namespace common {
namespace mysql_client {
Expand Down

0 comments on commit ded3774

Please sign in to comment.