aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2023-02-19 12:55:41 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2023-02-19 12:55:41 +0300
commit91783472c47040a949cc95ab0bb81f568e17d82f (patch)
tree2b2d7a0751d03509109405ebad9395fd609f296b
parentdd651aa6501e525bd07a5a84fe20a3252e81dafb (diff)
downloadydb-91783472c47040a949cc95ab0bb81f568e17d82f.tar.gz
Update contrib/restricted/aws/aws-c-io to 0.13.15
-rw-r--r--contrib/restricted/aws/aws-c-io/include/aws/io/retry_strategy.h25
-rw-r--r--contrib/restricted/aws/aws-c-io/source/channel_bootstrap.c41
-rw-r--r--contrib/restricted/aws/aws-c-io/source/exponential_backoff_retry_strategy.c32
-rw-r--r--contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c2
-rw-r--r--contrib/restricted/aws/aws-c-io/source/posix/socket.c2
5 files changed, 82 insertions, 20 deletions
diff --git a/contrib/restricted/aws/aws-c-io/include/aws/io/retry_strategy.h b/contrib/restricted/aws/aws-c-io/include/aws/io/retry_strategy.h
index 0c447aa71c..4d7a26f7e3 100644
--- a/contrib/restricted/aws/aws-c-io/include/aws/io/retry_strategy.h
+++ b/contrib/restricted/aws/aws-c-io/include/aws/io/retry_strategy.h
@@ -35,6 +35,11 @@ typedef void(aws_retry_strategy_on_retry_token_acquired_fn)(
*/
typedef void(aws_retry_strategy_on_retry_ready_fn)(struct aws_retry_token *token, int error_code, void *user_data);
+/**
+ * Optional function to supply your own generate random implementation
+ */
+typedef uint64_t(aws_generate_random_fn)(void *user_data);
+
enum aws_retry_error_type {
/** This is a connection level error such as a socket timeout, socket connect error, tls negotiation timeout etc...
* Typically these should never be applied for non-idempotent request types since in this scenario, it's impossible
@@ -108,8 +113,26 @@ struct aws_exponential_backoff_retry_options {
/** Jitter mode to use, see comments for aws_exponential_backoff_jitter_mode.
* Default is AWS_EXPONENTIAL_BACKOFF_JITTER_DEFAULT */
enum aws_exponential_backoff_jitter_mode jitter_mode;
- /** By default this will be set to use aws_device_random. If you want something else, set it here. */
+
+ /** Deprecated. Use generate_random_impl instead
+ * By default this will be set to use aws_device_random. If you want something else, set it here.
+ * */
uint64_t (*generate_random)(void);
+
+ /*
+ * By default this will be set to use aws_device_random. If you want something else, set it here.
+ */
+ aws_generate_random_fn *generate_random_impl;
+ /**
+ * Optional user data for the generate random generate_random_impl.
+ */
+ void *generate_random_user_data;
+
+ /**
+ * Optional shutdown callback that gets invoked, with appropriate user data,
+ * when the resources used by the retry_strategy are no longer in use.
+ */
+ const struct aws_shutdown_callback_options *shutdown_options;
};
struct aws_standard_retry_options {
diff --git a/contrib/restricted/aws/aws-c-io/source/channel_bootstrap.c b/contrib/restricted/aws/aws-c-io/source/channel_bootstrap.c
index 0f92399b90..2c351b0d0a 100644
--- a/contrib/restricted/aws/aws-c-io/source/channel_bootstrap.c
+++ b/contrib/restricted/aws/aws-c-io/source/channel_bootstrap.c
@@ -25,7 +25,7 @@
static void s_client_bootstrap_destroy_impl(struct aws_client_bootstrap *bootstrap) {
AWS_ASSERT(bootstrap);
- AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: destroying", (void *)bootstrap);
+ AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: bootstrap destroying", (void *)bootstrap);
aws_client_bootstrap_shutdown_complete_fn *on_shutdown_complete = bootstrap->on_shutdown_complete;
void *user_data = bootstrap->user_data;
@@ -41,6 +41,7 @@ static void s_client_bootstrap_destroy_impl(struct aws_client_bootstrap *bootstr
struct aws_client_bootstrap *aws_client_bootstrap_acquire(struct aws_client_bootstrap *bootstrap) {
if (bootstrap != NULL) {
+ AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: acquiring bootstrap reference", (void *)bootstrap);
aws_ref_count_acquire(&bootstrap->ref_count);
}
@@ -48,8 +49,8 @@ struct aws_client_bootstrap *aws_client_bootstrap_acquire(struct aws_client_boot
}
void aws_client_bootstrap_release(struct aws_client_bootstrap *bootstrap) {
- AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: releasing bootstrap reference", (void *)bootstrap);
if (bootstrap != NULL) {
+ AWS_LOGF_DEBUG(AWS_LS_IO_CHANNEL_BOOTSTRAP, "id=%p: releasing bootstrap reference", (void *)bootstrap);
aws_ref_count_release(&bootstrap->ref_count);
}
}
@@ -144,6 +145,7 @@ struct client_connection_args {
static struct client_connection_args *s_client_connection_args_acquire(struct client_connection_args *args) {
if (args != NULL) {
+ AWS_LOGF_TRACE(AWS_LS_IO_CHANNEL_BOOTSTRAP, "acquiring client connection args, args=%p", (void *)args);
aws_ref_count_acquire(&args->ref_count);
}
@@ -152,6 +154,7 @@ static struct client_connection_args *s_client_connection_args_acquire(struct cl
static void s_client_connection_args_destroy(struct client_connection_args *args) {
AWS_ASSERT(args);
+ AWS_LOGF_TRACE(AWS_LS_IO_CHANNEL_BOOTSTRAP, "destroying client connection args, args=%p", (void *)args);
struct aws_allocator *allocator = args->bootstrap->allocator;
aws_client_bootstrap_release(args->bootstrap);
@@ -168,6 +171,7 @@ static void s_client_connection_args_destroy(struct client_connection_args *args
static void s_client_connection_args_release(struct client_connection_args *args) {
if (args != NULL) {
+ AWS_LOGF_TRACE(AWS_LS_IO_CHANNEL_BOOTSTRAP, "releasing client connection args, args=%p", (void *)args);
aws_ref_count_release(&args->ref_count);
}
}
@@ -189,18 +193,17 @@ static void s_connection_args_setup_callback(
int error_code,
struct aws_channel *channel) {
/* setup_callback is always called exactly once */
- AWS_ASSERT(!args->setup_called);
- if (!args->setup_called) {
- AWS_ASSERT((error_code == AWS_OP_SUCCESS) == (channel != NULL));
- aws_client_bootstrap_on_channel_event_fn *setup_callback = args->setup_callback;
- setup_callback(args->bootstrap, error_code, channel, args->user_data);
- args->setup_called = true;
- /* if setup_callback is called with an error, we will not call shutdown_callback */
- if (error_code) {
- args->shutdown_callback = NULL;
- }
- s_client_connection_args_release(args);
+ AWS_FATAL_ASSERT(!args->setup_called);
+
+ AWS_ASSERT((error_code == AWS_OP_SUCCESS) == (channel != NULL));
+ aws_client_bootstrap_on_channel_event_fn *setup_callback = args->setup_callback;
+ setup_callback(args->bootstrap, error_code, channel, args->user_data);
+ args->setup_called = true;
+ /* if setup_callback is called with an error, we will not call shutdown_callback */
+ if (error_code) {
+ args->shutdown_callback = NULL;
}
+ s_client_connection_args_release(args);
}
static void s_connection_args_creation_callback(struct client_connection_args *args, struct aws_channel *channel) {
@@ -696,9 +699,19 @@ static void s_on_host_resolved(
/* ...then schedule all the tasks, which cannot fail */
for (size_t i = 0; i < host_addresses_len; ++i) {
struct connection_task_data *task_data = tasks[i];
- /* each task needs to hold a ref to the args until completed */
+ /**
+ * Acquire on the connection args to make sure connection args outlive the tasks to attempt connection.
+ *
+ * Once upon a time, the connection attempt tasks were scheduled right after acquiring the connection args,
+ * which lead to a crash that when the attempt connection tasks run and the attempt connection succeed and
+ * closed before the other tasks can acquire on the connection args, the connection args had be destroyed before
+ * acquire and lead to a crash.
+ */
s_client_connection_args_acquire(task_data->args);
+ }
+ for (size_t i = 0; i < host_addresses_len; ++i) {
+ struct connection_task_data *task_data = tasks[i];
aws_task_init(&task_data->task, s_attempt_connection, task_data, "attempt_connection");
aws_event_loop_schedule_task_now(connect_loop, &task_data->task);
}
diff --git a/contrib/restricted/aws/aws-c-io/source/exponential_backoff_retry_strategy.c b/contrib/restricted/aws/aws-c-io/source/exponential_backoff_retry_strategy.c
index eee20360e7..298cca9af1 100644
--- a/contrib/restricted/aws/aws-c-io/source/exponential_backoff_retry_strategy.c
+++ b/contrib/restricted/aws/aws-c-io/source/exponential_backoff_retry_strategy.c
@@ -17,6 +17,7 @@
struct exponential_backoff_strategy {
struct aws_retry_strategy base;
struct aws_exponential_backoff_retry_options config;
+ struct aws_shutdown_callback_options shutdown_options;
};
struct exponential_backoff_retry_token {
@@ -29,6 +30,8 @@ struct exponential_backoff_retry_token {
/* Let's not make this worse by constantly moving across threads if we can help it */
struct aws_event_loop *bound_loop;
uint64_t (*generate_random)(void);
+ aws_generate_random_fn *generate_random_impl;
+ void *generate_random_user_data;
struct aws_task retry_task;
struct {
@@ -43,7 +46,14 @@ static void s_exponential_retry_destroy(struct aws_retry_strategy *retry_strateg
if (retry_strategy) {
struct exponential_backoff_strategy *exponential_strategy = retry_strategy->impl;
struct aws_event_loop_group *el_group = exponential_strategy->config.el_group;
+ aws_simple_completion_callback *completion_callback =
+ exponential_strategy->shutdown_options.shutdown_callback_fn;
+ void *completion_user_data = exponential_strategy->shutdown_options.shutdown_callback_user_data;
+
aws_mem_release(retry_strategy->allocator, exponential_strategy);
+ if (completion_callback != NULL) {
+ completion_callback(completion_user_data);
+ }
aws_ref_count_release(&el_group->ref_count);
}
}
@@ -131,6 +141,9 @@ static int s_exponential_retry_acquire_token(
exponential_backoff_strategy->config.backoff_scale_factor_ms, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL);
backoff_retry_token->jitter_mode = exponential_backoff_strategy->config.jitter_mode;
backoff_retry_token->generate_random = exponential_backoff_strategy->config.generate_random;
+ backoff_retry_token->generate_random_impl = exponential_backoff_strategy->config.generate_random_impl;
+ backoff_retry_token->generate_random_user_data = exponential_backoff_strategy->config.generate_random_user_data;
+
aws_atomic_init_int(&backoff_retry_token->current_retry_count, 0);
aws_atomic_init_int(&backoff_retry_token->last_backoff, 0);
@@ -158,8 +171,12 @@ static inline uint64_t s_random_in_range(uint64_t from, uint64_t to, struct expo
if (!diff) {
return 0;
}
-
- uint64_t random = token->generate_random();
+ uint64_t random;
+ if (token->generate_random_impl) {
+ random = token->generate_random_impl(token->generate_random_user_data);
+ } else {
+ random = token->generate_random();
+ }
return min + random % (diff);
}
@@ -297,7 +314,8 @@ static struct aws_retry_strategy_vtable s_exponential_retry_vtable = {
.release_token = s_exponential_backoff_release_token,
};
-static uint64_t s_default_gen_rand(void) {
+static uint64_t s_default_gen_rand(void *user_data) {
+ (void)user_data;
uint64_t res = 0;
aws_device_random_u64(&res);
return res;
@@ -341,8 +359,9 @@ struct aws_retry_strategy *aws_retry_strategy_new_exponential_backoff(
exponential_backoff_strategy->config.el_group =
aws_ref_count_acquire(&exponential_backoff_strategy->config.el_group->ref_count);
- if (!exponential_backoff_strategy->config.generate_random) {
- exponential_backoff_strategy->config.generate_random = s_default_gen_rand;
+ if (!exponential_backoff_strategy->config.generate_random &&
+ !exponential_backoff_strategy->config.generate_random_impl) {
+ exponential_backoff_strategy->config.generate_random_impl = s_default_gen_rand;
}
if (!exponential_backoff_strategy->config.max_retries) {
@@ -353,5 +372,8 @@ struct aws_retry_strategy *aws_retry_strategy_new_exponential_backoff(
exponential_backoff_strategy->config.backoff_scale_factor_ms = 25;
}
+ if (config->shutdown_options) {
+ exponential_backoff_strategy->shutdown_options = *config->shutdown_options;
+ }
return &exponential_backoff_strategy->base;
}
diff --git a/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c b/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
index 3cf934b489..e4aafb838a 100644
--- a/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
+++ b/contrib/restricted/aws/aws-c-io/source/posix/host_resolver.c
@@ -38,7 +38,9 @@ int aws_default_dns_resolve(
AWS_ZERO_STRUCT(hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
+# if !defined(__OpenBSD__)
hints.ai_flags = AI_ALL | AI_V4MAPPED;
+# endif /* __OpenBSD__ */
int err_code = getaddrinfo(hostname_cstr, NULL, &hints, &result);
#endif
diff --git a/contrib/restricted/aws/aws-c-io/source/posix/socket.c b/contrib/restricted/aws/aws-c-io/source/posix/socket.c
index 7adf970c77..7dc170ccea 100644
--- a/contrib/restricted/aws/aws-c-io/source/posix/socket.c
+++ b/contrib/restricted/aws/aws-c-io/source/posix/socket.c
@@ -1272,6 +1272,7 @@ int aws_socket_set_options(struct aws_socket *socket, const struct aws_socket_op
}
}
+#if !defined(__OpenBSD__)
if (socket->options.keep_alive_interval_sec && socket->options.keep_alive_timeout_sec) {
int ival_in_secs = socket->options.keep_alive_interval_sec;
if (AWS_UNLIKELY(setsockopt(
@@ -1311,6 +1312,7 @@ int aws_socket_set_options(struct aws_socket *socket, const struct aws_socket_op
errno_value);
}
}
+#endif /* __OpenBSD__ */
}
return AWS_OP_SUCCESS;