Merge pull request #13917 from murgatroid99/uv_tcp_errors_unavailable_status

Mark tcp errors as UNAVAILABLE in UV tcp code
pull/13931/head
Michael Lumish 7 years ago committed by GitHub
commit ca8650adf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/core/lib/iomgr/tcp_uv.cc

@ -65,6 +65,17 @@ typedef struct {
grpc_pollset* pollset; grpc_pollset* pollset;
} grpc_tcp; } grpc_tcp;
static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) {
return grpc_error_set_str(
grpc_error_set_int(
src_error,
/* All tcp errors are marked with UNAVAILABLE so that application may
* choose to retry. */
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE),
GRPC_ERROR_STR_TARGET_ADDRESS,
grpc_slice_from_copied_string(tcp->peer_string));
}
static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) { static void tcp_free(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp) {
grpc_resource_user_unref(exec_ctx, tcp->resource_user); grpc_resource_user_unref(exec_ctx, tcp->resource_user);
gpr_free(tcp->handle); gpr_free(tcp->handle);
@ -166,7 +177,8 @@ static void read_callback(uv_stream_t* stream, ssize_t nread,
// TODO(murgatroid99): figure out what the return value here means // TODO(murgatroid99): figure out what the return value here means
uv_read_stop(stream); uv_read_stop(stream);
if (nread == UV_EOF) { if (nread == UV_EOF) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); error =
tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp);
grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices);
} else if (nread > 0) { } else if (nread > 0) {
// Successful read // Successful read
@ -181,7 +193,8 @@ static void read_callback(uv_stream_t* stream, ssize_t nread,
} }
} else { } else {
// nread < 0: Error // nread < 0: Error
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"); error = tcp_annotate_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"), tcp);
grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices); grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, tcp->read_slices);
} }
call_read_cb(&exec_ctx, tcp, error); call_read_cb(&exec_ctx, tcp, error);
@ -200,7 +213,9 @@ static void tcp_read_allocation_done(grpc_exec_ctx* exec_ctx, void* tcpp,
status = status =
uv_read_start((uv_stream_t*)tcp->handle, alloc_uv_buf, read_callback); uv_read_start((uv_stream_t*)tcp->handle, alloc_uv_buf, read_callback);
if (status != 0) { if (status != 0) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed at start"); error = tcp_annotate_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed at start"),
tcp);
error = grpc_error_set_str( error = grpc_error_set_str(
error, GRPC_ERROR_STR_OS_ERROR, error, GRPC_ERROR_STR_OS_ERROR,
grpc_slice_from_static_string(uv_strerror(status))); grpc_slice_from_static_string(uv_strerror(status)));
@ -241,7 +256,8 @@ static void write_callback(uv_write_t* req, int status) {
if (status == 0) { if (status == 0) {
error = GRPC_ERROR_NONE; error = GRPC_ERROR_NONE;
} else { } else {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed"); error = tcp_annotate_error(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed"), tcp);
} }
if (grpc_tcp_trace.enabled()) { if (grpc_tcp_trace.enabled()) {
const char* str = grpc_error_string(error); const char* str = grpc_error_string(error);
@ -275,9 +291,10 @@ static void uv_endpoint_write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep,
} }
if (tcp->shutting_down) { if (tcp->shutting_down) {
GRPC_CLOSURE_SCHED( GRPC_CLOSURE_SCHED(exec_ctx, cb,
exec_ctx, cb, tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP socket is shutting down")); "TCP socket is shutting down"),
tcp));
return; return;
} }

Loading…
Cancel
Save