|
|
@ -54,16 +54,16 @@ struct channel_data { |
|
|
|
grpc_channel_stack* channel_stack; |
|
|
|
grpc_channel_stack* channel_stack; |
|
|
|
/* Guards access to max_age_timer, max_age_timer_pending, max_age_grace_timer
|
|
|
|
/* Guards access to max_age_timer, max_age_timer_pending, max_age_grace_timer
|
|
|
|
and max_age_grace_timer_pending */ |
|
|
|
and max_age_grace_timer_pending */ |
|
|
|
gpr_mu max_age_timer_mu; |
|
|
|
grpc_core::Mutex max_age_timer_mu; |
|
|
|
/* True if the max_age timer callback is currently pending */ |
|
|
|
/* True if the max_age timer callback is currently pending */ |
|
|
|
bool max_age_timer_pending; |
|
|
|
bool max_age_timer_pending ABSL_GUARDED_BY(max_age_timer_mu) = false; |
|
|
|
/* True if the max_age_grace timer callback is currently pending */ |
|
|
|
/* True if the max_age_grace timer callback is currently pending */ |
|
|
|
bool max_age_grace_timer_pending; |
|
|
|
bool max_age_grace_timer_pending ABSL_GUARDED_BY(max_age_timer_mu) = false; |
|
|
|
/* The timer for checking if the channel has reached its max age */ |
|
|
|
/* The timer for checking if the channel has reached its max age */ |
|
|
|
grpc_timer max_age_timer; |
|
|
|
grpc_timer max_age_timer ABSL_GUARDED_BY(max_age_timer_mu); |
|
|
|
/* The timer for checking if the max-aged channel has uesed up the grace
|
|
|
|
/* The timer for checking if the max-aged channel has uesed up the grace
|
|
|
|
period */ |
|
|
|
period */ |
|
|
|
grpc_timer max_age_grace_timer; |
|
|
|
grpc_timer max_age_grace_timer ABSL_GUARDED_BY(max_age_timer_mu); |
|
|
|
/* The timer for checking if the channel's idle duration reaches
|
|
|
|
/* The timer for checking if the channel's idle duration reaches
|
|
|
|
max_connection_idle */ |
|
|
|
max_connection_idle */ |
|
|
|
grpc_timer max_idle_timer; |
|
|
|
grpc_timer max_idle_timer; |
|
|
@ -260,13 +260,15 @@ class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface { |
|
|
|
|
|
|
|
|
|
|
|
static void start_max_age_timer_after_init(void* arg, grpc_error* /*error*/) { |
|
|
|
static void start_max_age_timer_after_init(void* arg, grpc_error* /*error*/) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
gpr_mu_lock(&chand->max_age_timer_mu); |
|
|
|
{ |
|
|
|
chand->max_age_timer_pending = true; |
|
|
|
grpc_core::MutexLock lock(&chand->max_age_timer_mu); |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); |
|
|
|
chand->max_age_timer_pending = true; |
|
|
|
grpc_timer_init(&chand->max_age_timer, |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer"); |
|
|
|
grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age, |
|
|
|
grpc_timer_init( |
|
|
|
&chand->close_max_age_channel); |
|
|
|
&chand->max_age_timer, |
|
|
|
gpr_mu_unlock(&chand->max_age_timer_mu); |
|
|
|
grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age, |
|
|
|
|
|
|
|
&chand->close_max_age_channel); |
|
|
|
|
|
|
|
} |
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
op->start_connectivity_watch.reset(new grpc_core::ConnectivityWatcher(chand)); |
|
|
|
op->start_connectivity_watch.reset(new grpc_core::ConnectivityWatcher(chand)); |
|
|
|
op->start_connectivity_watch_state = GRPC_CHANNEL_IDLE; |
|
|
|
op->start_connectivity_watch_state = GRPC_CHANNEL_IDLE; |
|
|
@ -278,16 +280,17 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* /*error*/) { |
|
|
|
static void start_max_age_grace_timer_after_goaway_op(void* arg, |
|
|
|
static void start_max_age_grace_timer_after_goaway_op(void* arg, |
|
|
|
grpc_error* /*error*/) { |
|
|
|
grpc_error* /*error*/) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
gpr_mu_lock(&chand->max_age_timer_mu); |
|
|
|
{ |
|
|
|
chand->max_age_grace_timer_pending = true; |
|
|
|
grpc_core::MutexLock lock(&chand->max_age_timer_mu); |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); |
|
|
|
chand->max_age_grace_timer_pending = true; |
|
|
|
grpc_timer_init( |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer"); |
|
|
|
&chand->max_age_grace_timer, |
|
|
|
grpc_timer_init(&chand->max_age_grace_timer, |
|
|
|
chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE |
|
|
|
chand->max_connection_age_grace == GRPC_MILLIS_INF_FUTURE |
|
|
|
? GRPC_MILLIS_INF_FUTURE |
|
|
|
? GRPC_MILLIS_INF_FUTURE |
|
|
|
: grpc_core::ExecCtx::Get()->Now() + chand->max_connection_age_grace, |
|
|
|
: grpc_core::ExecCtx::Get()->Now() + |
|
|
|
&chand->force_close_max_age_channel); |
|
|
|
chand->max_connection_age_grace, |
|
|
|
gpr_mu_unlock(&chand->max_age_timer_mu); |
|
|
|
&chand->force_close_max_age_channel); |
|
|
|
|
|
|
|
} |
|
|
|
GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, |
|
|
|
GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, |
|
|
|
"max_age start_max_age_grace_timer_after_goaway_op"); |
|
|
|
"max_age start_max_age_grace_timer_after_goaway_op"); |
|
|
|
} |
|
|
|
} |
|
|
@ -350,9 +353,10 @@ static void max_idle_timer_cb(void* arg, grpc_error* error) { |
|
|
|
|
|
|
|
|
|
|
|
static void close_max_age_channel(void* arg, grpc_error* error) { |
|
|
|
static void close_max_age_channel(void* arg, grpc_error* error) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
gpr_mu_lock(&chand->max_age_timer_mu); |
|
|
|
{ |
|
|
|
chand->max_age_timer_pending = false; |
|
|
|
grpc_core::MutexLock lock(&chand->max_age_timer_mu); |
|
|
|
gpr_mu_unlock(&chand->max_age_timer_mu); |
|
|
|
chand->max_age_timer_pending = false; |
|
|
|
|
|
|
|
} |
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, |
|
|
|
GRPC_CHANNEL_STACK_REF(chand->channel_stack, |
|
|
|
"max_age start_max_age_grace_timer_after_goaway_op"); |
|
|
|
"max_age start_max_age_grace_timer_after_goaway_op"); |
|
|
@ -372,9 +376,10 @@ static void close_max_age_channel(void* arg, grpc_error* error) { |
|
|
|
|
|
|
|
|
|
|
|
static void force_close_max_age_channel(void* arg, grpc_error* error) { |
|
|
|
static void force_close_max_age_channel(void* arg, grpc_error* error) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
channel_data* chand = static_cast<channel_data*>(arg); |
|
|
|
gpr_mu_lock(&chand->max_age_timer_mu); |
|
|
|
{ |
|
|
|
chand->max_age_grace_timer_pending = false; |
|
|
|
grpc_core::MutexLock lock(&chand->max_age_timer_mu); |
|
|
|
gpr_mu_unlock(&chand->max_age_timer_mu); |
|
|
|
chand->max_age_grace_timer_pending = false; |
|
|
|
|
|
|
|
} |
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
grpc_transport_op* op = grpc_make_transport_op(nullptr); |
|
|
|
op->disconnect_with_error = |
|
|
|
op->disconnect_with_error = |
|
|
@ -426,9 +431,7 @@ static void max_age_destroy_call_elem( |
|
|
|
static grpc_error* max_age_init_channel_elem(grpc_channel_element* elem, |
|
|
|
static grpc_error* max_age_init_channel_elem(grpc_channel_element* elem, |
|
|
|
grpc_channel_element_args* args) { |
|
|
|
grpc_channel_element_args* args) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data); |
|
|
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data); |
|
|
|
gpr_mu_init(&chand->max_age_timer_mu); |
|
|
|
new (chand) channel_data(); |
|
|
|
chand->max_age_timer_pending = false; |
|
|
|
|
|
|
|
chand->max_age_grace_timer_pending = false; |
|
|
|
|
|
|
|
chand->channel_stack = args->channel_stack; |
|
|
|
chand->channel_stack = args->channel_stack; |
|
|
|
chand->max_connection_age = |
|
|
|
chand->max_connection_age = |
|
|
|
add_random_max_connection_age_jitter_and_convert_to_grpc_millis( |
|
|
|
add_random_max_connection_age_jitter_and_convert_to_grpc_millis( |
|
|
@ -513,7 +516,7 @@ static grpc_error* max_age_init_channel_elem(grpc_channel_element* elem, |
|
|
|
/* Destructor for channel_data. */ |
|
|
|
/* Destructor for channel_data. */ |
|
|
|
static void max_age_destroy_channel_elem(grpc_channel_element* elem) { |
|
|
|
static void max_age_destroy_channel_elem(grpc_channel_element* elem) { |
|
|
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data); |
|
|
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data); |
|
|
|
gpr_mu_destroy(&chand->max_age_timer_mu); |
|
|
|
chand->~channel_data(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const grpc_channel_filter grpc_max_age_filter = { |
|
|
|
const grpc_channel_filter grpc_max_age_filter = { |
|
|
|