diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-08-01 16:20:17 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-08-01 16:21:43 -0700 |
commit | 791e78ad94d394716c32e04d877fe628b13ef254 (patch) | |
tree | 8fd6deee8eb6f9af8a2195dfd564b3fa8e4bd639 /src/core/surface | |
parent | 489df079ae948a4ea695a3e8f27b6e0a43d5daf1 (diff) |
Dont crash on too many pluckers
Diffstat (limited to 'src/core/surface')
-rw-r--r-- | src/core/surface/completion_queue.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 6bfccd2a2e..9d6f78db55 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -201,12 +201,15 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, return ret; } -static void add_plucker(grpc_completion_queue *cc, void *tag, - grpc_pollset_worker *worker) { - GPR_ASSERT(cc->num_pluckers != GRPC_MAX_COMPLETION_QUEUE_PLUCKERS); +static int add_plucker(grpc_completion_queue *cc, void *tag, + grpc_pollset_worker *worker) { + if (cc->num_pluckers == GRPC_MAX_COMPLETION_QUEUE_PLUCKERS) { + return 0; + } cc->pluckers[cc->num_pluckers].tag = tag; cc->pluckers[cc->num_pluckers].worker = worker; cc->num_pluckers++; + return 1; } static void del_plucker(grpc_completion_queue *cc, void *tag, @@ -259,7 +262,16 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, ret.type = GRPC_QUEUE_SHUTDOWN; break; } - add_plucker(cc, tag, &worker); + if (!add_plucker(cc, tag, &worker)) { + gpr_log(GPR_DEBUG, + "Too many outstanding grpc_completion_queue_pluck calls: maximum is %d". + GRPC_MAX_COMPLETION_QUEUE_PLUCKERS); + gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); + memset(&ret, 0, sizeof(ret)); + /* TODO(ctiller): should we use a different result here */ + ret.type = GRPC_QUEUE_TIMEOUT; + break; + } if (!grpc_pollset_work(&cc->pollset, &worker, deadline)) { del_plucker(cc, tag, &worker); gpr_mu_unlock(GRPC_POLLSET_MU(&cc->pollset)); |