|
|
@ -64,6 +64,11 @@ |
|
|
|
#define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS false |
|
|
|
#define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS false |
|
|
|
#define KEEPALIVE_TIME_BACKOFF_MULTIPLIER 2 |
|
|
|
#define KEEPALIVE_TIME_BACKOFF_MULTIPLIER 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS 300000 /* 5 minutes */ |
|
|
|
|
|
|
|
#define DEFAULT_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS 300000 /* 5 minutes */ |
|
|
|
|
|
|
|
#define DEFAULT_MAX_PINGS_BETWEEN_DATA 0 /* unlimited */ |
|
|
|
|
|
|
|
#define DEFAULT_MAX_PING_STRIKES 2 |
|
|
|
|
|
|
|
|
|
|
|
static int g_default_client_keepalive_time_ms = |
|
|
|
static int g_default_client_keepalive_time_ms = |
|
|
|
DEFAULT_CLIENT_KEEPALIVE_TIME_MS; |
|
|
|
DEFAULT_CLIENT_KEEPALIVE_TIME_MS; |
|
|
|
static int g_default_client_keepalive_timeout_ms = |
|
|
|
static int g_default_client_keepalive_timeout_ms = |
|
|
@ -75,6 +80,13 @@ static int g_default_server_keepalive_timeout_ms = |
|
|
|
static bool g_default_keepalive_permit_without_calls = |
|
|
|
static bool g_default_keepalive_permit_without_calls = |
|
|
|
DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS; |
|
|
|
DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int g_default_min_sent_ping_interval_without_data_ms = |
|
|
|
|
|
|
|
DEFAULT_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS; |
|
|
|
|
|
|
|
static int g_default_min_recv_ping_interval_without_data_ms = |
|
|
|
|
|
|
|
DEFAULT_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS; |
|
|
|
|
|
|
|
static int g_default_max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA; |
|
|
|
|
|
|
|
static int g_default_max_ping_strikes = DEFAULT_MAX_PING_STRIKES; |
|
|
|
|
|
|
|
|
|
|
|
#define MAX_CLIENT_STREAM_ID 0x7fffffffu |
|
|
|
#define MAX_CLIENT_STREAM_ID 0x7fffffffu |
|
|
|
grpc_tracer_flag grpc_http_trace = GRPC_TRACER_INITIALIZER(false, "http"); |
|
|
|
grpc_tracer_flag grpc_http_trace = GRPC_TRACER_INITIALIZER(false, "http"); |
|
|
|
grpc_tracer_flag grpc_flowctl_trace = GRPC_TRACER_INITIALIZER(false, "flowctl"); |
|
|
|
grpc_tracer_flag grpc_flowctl_trace = GRPC_TRACER_INITIALIZER(false, "flowctl"); |
|
|
@ -150,11 +162,6 @@ static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, |
|
|
|
static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, |
|
|
|
grpc_error *error); |
|
|
|
grpc_error *error); |
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_MIN_TIME_BETWEEN_PINGS_MS 0 |
|
|
|
|
|
|
|
#define DEFAULT_MAX_PINGS_BETWEEN_DATA 3 |
|
|
|
|
|
|
|
#define DEFAULT_MAX_PING_STRIKES 2 |
|
|
|
|
|
|
|
#define DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS 300000 /* 5 minutes */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** keepalive-relevant functions */ |
|
|
|
/** keepalive-relevant functions */ |
|
|
|
static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
grpc_error *error); |
|
|
|
grpc_error *error); |
|
|
@ -361,12 +368,12 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1); |
|
|
|
GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1); |
|
|
|
|
|
|
|
|
|
|
|
t->ping_policy = (grpc_chttp2_repeated_ping_policy){ |
|
|
|
t->ping_policy = (grpc_chttp2_repeated_ping_policy){ |
|
|
|
.max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA, |
|
|
|
.max_pings_without_data = g_default_max_pings_without_data, |
|
|
|
.min_time_between_pings = |
|
|
|
.min_sent_ping_interval_without_data = gpr_time_from_millis( |
|
|
|
gpr_time_from_millis(DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, GPR_TIMESPAN), |
|
|
|
g_default_min_sent_ping_interval_without_data_ms, GPR_TIMESPAN), |
|
|
|
.max_ping_strikes = DEFAULT_MAX_PING_STRIKES, |
|
|
|
.max_ping_strikes = g_default_max_ping_strikes, |
|
|
|
.min_ping_interval_without_data = gpr_time_from_millis( |
|
|
|
.min_recv_ping_interval_without_data = gpr_time_from_millis( |
|
|
|
DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, GPR_TIMESPAN), |
|
|
|
g_default_min_recv_ping_interval_without_data_ms, GPR_TIMESPAN), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/* Keepalive setting */ |
|
|
|
/* Keepalive setting */ |
|
|
@ -426,28 +433,36 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { |
|
|
|
GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { |
|
|
|
t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer( |
|
|
|
t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer( |
|
|
|
&channel_args->args[i], |
|
|
|
&channel_args->args[i], |
|
|
|
(grpc_integer_options){DEFAULT_MAX_PINGS_BETWEEN_DATA, 0, INT_MAX}); |
|
|
|
(grpc_integer_options){g_default_max_pings_without_data, 0, |
|
|
|
|
|
|
|
INT_MAX}); |
|
|
|
} else if (0 == strcmp(channel_args->args[i].key, |
|
|
|
} else if (0 == strcmp(channel_args->args[i].key, |
|
|
|
GRPC_ARG_HTTP2_MAX_PING_STRIKES)) { |
|
|
|
GRPC_ARG_HTTP2_MAX_PING_STRIKES)) { |
|
|
|
t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer( |
|
|
|
t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer( |
|
|
|
&channel_args->args[i], |
|
|
|
&channel_args->args[i], |
|
|
|
(grpc_integer_options){DEFAULT_MAX_PING_STRIKES, 0, INT_MAX}); |
|
|
|
(grpc_integer_options){g_default_max_ping_strikes, 0, INT_MAX}); |
|
|
|
} else if (0 == strcmp(channel_args->args[i].key, |
|
|
|
} else if (0 == |
|
|
|
GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS)) { |
|
|
|
strcmp( |
|
|
|
t->ping_policy.min_time_between_pings = gpr_time_from_millis( |
|
|
|
channel_args->args[i].key, |
|
|
|
|
|
|
|
GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS)) { |
|
|
|
|
|
|
|
t->ping_policy.min_sent_ping_interval_without_data = |
|
|
|
|
|
|
|
gpr_time_from_millis( |
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
&channel_args->args[i], |
|
|
|
&channel_args->args[i], |
|
|
|
(grpc_integer_options){DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, 0, |
|
|
|
(grpc_integer_options){ |
|
|
|
|
|
|
|
g_default_min_sent_ping_interval_without_data_ms, 0, |
|
|
|
INT_MAX}), |
|
|
|
INT_MAX}), |
|
|
|
GPR_TIMESPAN); |
|
|
|
GPR_TIMESPAN); |
|
|
|
} else if (0 == |
|
|
|
} else if (0 == |
|
|
|
strcmp(channel_args->args[i].key, |
|
|
|
strcmp( |
|
|
|
GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS)) { |
|
|
|
channel_args->args[i].key, |
|
|
|
t->ping_policy.min_ping_interval_without_data = gpr_time_from_millis( |
|
|
|
GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)) { |
|
|
|
|
|
|
|
t->ping_policy.min_recv_ping_interval_without_data = |
|
|
|
|
|
|
|
gpr_time_from_millis( |
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
&channel_args->args[i], |
|
|
|
&channel_args->args[i], |
|
|
|
(grpc_integer_options){ |
|
|
|
(grpc_integer_options){ |
|
|
|
DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, 0, INT_MAX}), |
|
|
|
g_default_min_recv_ping_interval_without_data_ms, 0, |
|
|
|
|
|
|
|
INT_MAX}), |
|
|
|
GPR_TIMESPAN); |
|
|
|
GPR_TIMESPAN); |
|
|
|
} else if (0 == strcmp(channel_args->args[i].key, |
|
|
|
} else if (0 == strcmp(channel_args->args[i].key, |
|
|
|
GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { |
|
|
|
GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { |
|
|
@ -555,8 +570,8 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
t->ping_state.pings_before_data_required = |
|
|
|
/* No pings allowed before receiving a header or data frame. */ |
|
|
|
t->ping_policy.max_pings_without_data; |
|
|
|
t->ping_state.pings_before_data_required = 0; |
|
|
|
t->ping_state.is_delayed_ping_timer_set = false; |
|
|
|
t->ping_state.is_delayed_ping_timer_set = false; |
|
|
|
|
|
|
|
|
|
|
|
t->ping_recv_state.last_ping_recv_time = gpr_inf_past(GPR_CLOCK_MONOTONIC); |
|
|
|
t->ping_recv_state.last_ping_recv_time = gpr_inf_past(GPR_CLOCK_MONOTONIC); |
|
|
@ -623,6 +638,9 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, |
|
|
|
connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_SHUTDOWN, |
|
|
|
connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_SHUTDOWN, |
|
|
|
GRPC_ERROR_REF(error), "close_transport"); |
|
|
|
GRPC_ERROR_REF(error), "close_transport"); |
|
|
|
grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error)); |
|
|
|
grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error)); |
|
|
|
|
|
|
|
if (t->ping_state.is_delayed_ping_timer_set) { |
|
|
|
|
|
|
|
grpc_timer_cancel(exec_ctx, &t->ping_state.delayed_ping_timer); |
|
|
|
|
|
|
|
} |
|
|
|
switch (t->keepalive_state) { |
|
|
|
switch (t->keepalive_state) { |
|
|
|
case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: |
|
|
|
case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: |
|
|
|
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); |
|
|
|
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); |
|
|
@ -1718,9 +1736,11 @@ static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp, |
|
|
|
grpc_error *error) { |
|
|
|
grpc_error *error) { |
|
|
|
grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; |
|
|
|
grpc_chttp2_transport *t = (grpc_chttp2_transport *)tp; |
|
|
|
t->ping_state.is_delayed_ping_timer_set = false; |
|
|
|
t->ping_state.is_delayed_ping_timer_set = false; |
|
|
|
|
|
|
|
if (error == GRPC_ERROR_NONE) { |
|
|
|
grpc_chttp2_initiate_write(exec_ctx, t, |
|
|
|
grpc_chttp2_initiate_write(exec_ctx, t, |
|
|
|
GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); |
|
|
|
GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, |
|
|
|
uint64_t id) { |
|
|
|
uint64_t id) { |
|
|
@ -2617,6 +2637,36 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args, |
|
|
|
&args->args[i], |
|
|
|
&args->args[i], |
|
|
|
(grpc_integer_options){g_default_keepalive_permit_without_calls, |
|
|
|
(grpc_integer_options){g_default_keepalive_permit_without_calls, |
|
|
|
0, 1}); |
|
|
|
0, 1}); |
|
|
|
|
|
|
|
} else if (0 == |
|
|
|
|
|
|
|
strcmp(args->args[i].key, GRPC_ARG_HTTP2_MAX_PING_STRIKES)) { |
|
|
|
|
|
|
|
g_default_max_ping_strikes = grpc_channel_arg_get_integer( |
|
|
|
|
|
|
|
&args->args[i], |
|
|
|
|
|
|
|
(grpc_integer_options){g_default_max_ping_strikes, 0, INT_MAX}); |
|
|
|
|
|
|
|
} else if (0 == strcmp(args->args[i].key, |
|
|
|
|
|
|
|
GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) { |
|
|
|
|
|
|
|
g_default_max_pings_without_data = grpc_channel_arg_get_integer( |
|
|
|
|
|
|
|
&args->args[i], (grpc_integer_options){ |
|
|
|
|
|
|
|
g_default_max_pings_without_data, 0, INT_MAX}); |
|
|
|
|
|
|
|
} else if (0 == |
|
|
|
|
|
|
|
strcmp( |
|
|
|
|
|
|
|
args->args[i].key, |
|
|
|
|
|
|
|
GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS)) { |
|
|
|
|
|
|
|
g_default_min_sent_ping_interval_without_data_ms = |
|
|
|
|
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
|
|
|
|
&args->args[i], |
|
|
|
|
|
|
|
(grpc_integer_options){ |
|
|
|
|
|
|
|
g_default_min_sent_ping_interval_without_data_ms, 0, |
|
|
|
|
|
|
|
INT_MAX}); |
|
|
|
|
|
|
|
} else if (0 == |
|
|
|
|
|
|
|
strcmp( |
|
|
|
|
|
|
|
args->args[i].key, |
|
|
|
|
|
|
|
GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)) { |
|
|
|
|
|
|
|
g_default_min_recv_ping_interval_without_data_ms = |
|
|
|
|
|
|
|
grpc_channel_arg_get_integer( |
|
|
|
|
|
|
|
&args->args[i], |
|
|
|
|
|
|
|
(grpc_integer_options){ |
|
|
|
|
|
|
|
g_default_min_recv_ping_interval_without_data_ms, 0, |
|
|
|
|
|
|
|
INT_MAX}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|