Fuzzing fixes

pull/6897/head
Craig Tiller 9 years ago
parent d039722f06
commit e0d6c57e15
  1. 2
      src/core/ext/client_config/channel_connectivity.c
  2. 13
      src/core/ext/client_config/subchannel.c
  3. 3
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  4. 21
      src/core/lib/iomgr/error.c
  5. 8
      src/core/lib/iomgr/error.h
  6. 1
      src/core/lib/iomgr/tcp_posix.c
  7. 2
      src/core/lib/transport/transport.h

@ -132,8 +132,6 @@ static void partly_done(grpc_exec_ctx *exec_ctx, state_watcher *w,
gpr_mu_lock(&w->mu); gpr_mu_lock(&w->mu);
const char *msg = grpc_error_string(error); const char *msg = grpc_error_string(error);
gpr_log(GPR_DEBUG, "partly_done: d2c=%d phs=%d err=%s", due_to_completion,
w->phase, msg);
grpc_error_free_string(msg); grpc_error_free_string(msg);
if (due_to_completion) { if (due_to_completion) {

@ -54,7 +54,7 @@
#define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1)) #define STRONG_REF_MASK (~(gpr_atm)((1 << INTERNAL_REF_BITS) - 1))
#define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20 #define GRPC_SUBCHANNEL_MIN_CONNECT_TIMEOUT_SECONDS 20
#define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 2 #define GRPC_SUBCHANNEL_INITIAL_CONNECT_BACKOFF_SECONDS 1
#define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6 #define GRPC_SUBCHANNEL_RECONNECT_BACKOFF_MULTIPLIER 1.6
#define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120 #define GRPC_SUBCHANNEL_RECONNECT_MAX_BACKOFF_SECONDS 120
#define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2 #define GRPC_SUBCHANNEL_RECONNECT_JITTER 0.2
@ -606,12 +606,8 @@ static void on_alarm(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
GRPC_ERROR_REF(error); GRPC_ERROR_REF(error);
} }
if (error == GRPC_ERROR_NONE) { if (error == GRPC_ERROR_NONE) {
const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Failed to connect to channel, retrying");
gpr_log(GPR_INFO, "Failed to connect to channel, retrying: %s", msg); c->next_attempt = gpr_backoff_step(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC));
grpc_error_free_string(msg);
c->next_attempt =
gpr_backoff_step(&c->backoff_state, gpr_now(GPR_CLOCK_MONOTONIC));
continue_connect(exec_ctx, c); continue_connect(exec_ctx, c);
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
} else { } else {
@ -639,8 +635,7 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg,
exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE, exec_ctx, &c->state_tracker, GRPC_CHANNEL_TRANSIENT_FAILURE,
GRPC_ERROR_CREATE_REFERENCING("Connect Failed", &error, 1), GRPC_ERROR_CREATE_REFERENCING("Connect Failed", &error, 1),
"connect_failed"); "connect_failed");
gpr_timespec time_til_next = gpr_timespec time_til_next = gpr_time_sub(c->next_attempt, now);
gpr_time_sub(c->next_attempt, gpr_now(c->next_attempt.clock_type));
const char *errmsg = grpc_error_string(error); const char *errmsg = grpc_error_string(error);
gpr_log(GPR_INFO, "Connect failed, retry in %d.%09d seconds: %s", gpr_log(GPR_INFO, "Connect failed, retry in %d.%09d seconds: %s",
time_til_next.tv_sec, time_til_next.tv_nsec, errmsg); time_til_next.tv_sec, time_til_next.tv_nsec, errmsg);

@ -781,13 +781,14 @@ static void terminate_writing_with_lock(grpc_exec_ctx *exec_ctx,
} }
UNREF_TRANSPORT(exec_ctx, t, "writing"); UNREF_TRANSPORT(exec_ctx, t, "writing");
GRPC_ERROR_UNREF(error);
} }
void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx, void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx,
void *transport_writing, grpc_error *error) { void *transport_writing, grpc_error *error) {
grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING(transport_writing); grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING(transport_writing);
grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL, grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL,
terminate_writing_with_lock, error, 0); terminate_writing_with_lock, GRPC_ERROR_REF(error), 0);
} }
static void writing_action(grpc_exec_ctx *exec_ctx, void *gt, static void writing_action(grpc_exec_ctx *exec_ctx, void *gt,

@ -158,6 +158,7 @@ static bool is_special(grpc_error *err) {
err == GRPC_ERROR_CANCELLED; err == GRPC_ERROR_CANCELLED;
} }
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line,
const char *func) { const char *func) {
if (is_special(err)) return err; if (is_special(err)) return err;
@ -166,6 +167,13 @@ grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line,
gpr_ref(&err->refs); gpr_ref(&err->refs);
return err; return err;
} }
#else
grpc_error *grpc_error_ref(grpc_error *err) {
if (is_special(err)) return err;
gpr_ref(&err->refs);
return err;
}
#endif
static void error_destroy(grpc_error *err) { static void error_destroy(grpc_error *err) {
GPR_ASSERT(!is_special(err)); GPR_ASSERT(!is_special(err));
@ -176,6 +184,7 @@ static void error_destroy(grpc_error *err) {
gpr_free(err); gpr_free(err);
} }
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
void grpc_error_unref(grpc_error *err, const char *file, int line, void grpc_error_unref(grpc_error *err, const char *file, int line,
const char *func) { const char *func) {
if (is_special(err)) return; if (is_special(err)) return;
@ -185,6 +194,14 @@ void grpc_error_unref(grpc_error *err, const char *file, int line,
error_destroy(err); error_destroy(err);
} }
} }
#else
void grpc_error_unref(grpc_error *err) {
if (is_special(err)) return;
if (gpr_unref(&err->refs)) {
error_destroy(err);
}
}
#endif
grpc_error *grpc_error_create(const char *file, int line, const char *desc, grpc_error *grpc_error_create(const char *file, int line, const char *desc,
grpc_error **referencing, grpc_error **referencing,
@ -193,7 +210,9 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc,
if (err == NULL) { // TODO(ctiller): make gpr_malloc return NULL if (err == NULL) { // TODO(ctiller): make gpr_malloc return NULL
return GRPC_ERROR_OOM; return GRPC_ERROR_OOM;
} }
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line); gpr_log(GPR_DEBUG, "%p create [%s:%d]", err, file, line);
#endif
err->ints = gpr_avl_add(gpr_avl_create(&avl_vtable_ints), err->ints = gpr_avl_add(gpr_avl_create(&avl_vtable_ints),
(void *)(uintptr_t)GRPC_ERROR_INT_FILE_LINE, (void *)(uintptr_t)GRPC_ERROR_INT_FILE_LINE,
(void *)(uintptr_t)line); (void *)(uintptr_t)line);
@ -223,7 +242,9 @@ static grpc_error *copy_error_and_unref(grpc_error *in) {
return GRPC_ERROR_CREATE("unknown"); return GRPC_ERROR_CREATE("unknown");
} }
grpc_error *out = gpr_malloc(sizeof(*out)); grpc_error *out = gpr_malloc(sizeof(*out));
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
gpr_log(GPR_DEBUG, "%p create copying", out); gpr_log(GPR_DEBUG, "%p create copying", out);
#endif
out->ints = gpr_avl_ref(in->ints); out->ints = gpr_avl_ref(in->ints);
out->strs = gpr_avl_ref(in->strs); out->strs = gpr_avl_ref(in->strs);
out->errs = gpr_avl_ref(in->errs); out->errs = gpr_avl_ref(in->errs);

@ -100,6 +100,8 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc,
#define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \ #define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \
grpc_error_create(__FILE__, __LINE__, desc, errs, count) grpc_error_create(__FILE__, __LINE__, desc, errs, count)
#define GRPC_ERROR_REFCOUNT_DEBUG
#ifdef GRPC_ERROR_REFCOUNT_DEBUG
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line,
const char *func); const char *func);
void grpc_error_unref(grpc_error *err, const char *file, int line, void grpc_error_unref(grpc_error *err, const char *file, int line,
@ -107,6 +109,12 @@ void grpc_error_unref(grpc_error *err, const char *file, int line,
#define GRPC_ERROR_REF(err) grpc_error_ref(err, __FILE__, __LINE__, __func__) #define GRPC_ERROR_REF(err) grpc_error_ref(err, __FILE__, __LINE__, __func__)
#define GRPC_ERROR_UNREF(err) \ #define GRPC_ERROR_UNREF(err) \
grpc_error_unref(err, __FILE__, __LINE__, __func__) grpc_error_unref(err, __FILE__, __LINE__, __func__)
#else
grpc_error *grpc_error_ref(grpc_error *err);
void grpc_error_unref(grpc_error *err);
#define GRPC_ERROR_REF(err) grpc_error_ref(err)
#define GRPC_ERROR_UNREF(err) grpc_error_unref(err)
#endif
grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which,
intptr_t value); intptr_t value);

@ -384,6 +384,7 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
cb->cb(exec_ctx, cb->cb_arg, error); cb->cb(exec_ctx, cb->cb_arg, error);
GPR_TIMER_END("tcp_handle_write.cb", 0); GPR_TIMER_END("tcp_handle_write.cb", 0);
TCP_UNREF(exec_ctx, tcp, "write"); TCP_UNREF(exec_ctx, tcp, "write");
GRPC_ERROR_UNREF(error);
} }
} }

@ -50,7 +50,7 @@ typedef struct grpc_transport grpc_transport;
for a stream. */ for a stream. */
typedef struct grpc_stream grpc_stream; typedef struct grpc_stream grpc_stream;
//#define GRPC_STREAM_REFCOUNT_DEBUG #define GRPC_STREAM_REFCOUNT_DEBUG
typedef struct grpc_stream_refcount { typedef struct grpc_stream_refcount {
gpr_refcount refs; gpr_refcount refs;

Loading…
Cancel
Save