Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add some return code checking and spealing stuffz

  • Loading branch information...
commit 81da23130de62a4022aada698179b9cf550ea702 1 parent 9f07373
jlindamood authored

Showing 1 changed file with 29 additions and 6 deletions. Show diff stats Hide diff stats

  1. +29 6 ngx_http_healthcheck_module.c
35 ngx_http_healthcheck_module.c
@@ -11,7 +11,7 @@
11 11 #include <ngx_http_healthcheck_module.h>
12 12
13 13 #if (!NGX_HAVE_ATOMIC_OPS)
14   -#error "Healthcheck module only works with atmoic ops"
  14 +#error "Healthcheck module only works with atomic ops"
15 15 #endif
16 16
17 17 typedef enum {
@@ -100,7 +100,8 @@ typedef struct {
100 100 // This one is not shared. Created when the config is parsed
101 101 static ngx_array_t *ngx_http_healthchecks_arr;
102 102 // This is the same as the above data ->elts. For ease of use
103   -static ngx_http_healthcheck_status_t *ngx_http_healthchecks;
  103 +#define ngx_http_healthchecks \
  104 + ((ngx_http_healthcheck_status_t*) ngx_http_healthchecks_arr->elts)
104 105 static ngx_http_healthcheck_status_shm_t *ngx_http_healthchecks_shm;
105 106
106 107 static ngx_int_t ngx_http_healthcheck_init(ngx_conf_t *cf);
@@ -300,7 +301,7 @@ void ngx_http_healthcheck_write_handler(ngx_event_t *wev) {
300 301
301 302 if (stat->state != NGX_HEALTH_SENDING_CHECK) {
302 303 ngx_log_debug(NGX_LOG_DEBUG_HTTP, wev->log, 0,
303   - "healthcheck: Ignoring a write. Not in writting state");
  304 + "healthcheck: Ignoring a write. Not in writing state");
304 305 return;
305 306 }
306 307
@@ -503,6 +504,7 @@ static ngx_int_t ngx_http_healthcheck_process_recv(
503 504 static void ngx_http_healthcheck_begin_healthcheck(ngx_event_t *event) {
504 505 ngx_http_healthcheck_status_t * stat;
505 506 ngx_connection_t *c;
  507 + ngx_int_t rc;
506 508
507 509 stat = event->data;
508 510 if (stat->state != NGX_HEALTH_WAITING) {
@@ -530,7 +532,23 @@ static void ngx_http_healthcheck_begin_healthcheck(ngx_event_t *event) {
530 532 ngx_log_debug(NGX_LOG_DEBUG_HTTP, event->log, 0,
531 533 "healthcheck: Connecting peer", stat->index);
532 534
533   - ngx_event_connect_peer(stat->pc);
  535 + rc = ngx_event_connect_peer(stat->pc);
  536 + if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
  537 + ngx_log_error(NGX_LOG_CRIT, event->log, 0,
  538 + "healthcheck: Could not connect to peer. This is"
  539 + " pretty bad and probably means your health checks won't"
  540 + " work anymore: %d", rc);
  541 + if (stat->pc->connection) {
  542 + ngx_close_connection(stat->pc->connection);
  543 + }
  544 + // Try to do it again later, but if you're getting errors when you
  545 + // try to connect to a peer, this probably won't work
  546 + ngx_add_timer(&stat->health_ev, stat->conf->health_delay);
  547 + return;
  548 + }
  549 + ngx_log_debug(NGX_LOG_DEBUG_HTTP, event->log, 0,
  550 + "healthcheck: connected so far");
  551 +
534 552
535 553 c = stat->pc->connection;
536 554 c->data = stat;
@@ -550,6 +568,9 @@ static void ngx_http_healthcheck_begin_healthcheck(ngx_event_t *event) {
550 568 stat->read_buffer->last = stat->read_buffer->start;
551 569 stat->check_start_time = ngx_current_msec;
552 570 ngx_add_timer(c->read, stat->conf->health_timeout);
  571 + ngx_log_debug(NGX_LOG_DEBUG_HTTP, event->log, 0,
  572 + "healthcheck: Peer connected", stat->index);
  573 +
553 574 }
554 575
555 576 static void ngx_http_healthcheck_try_for_ownership(ngx_event_t *event) {
@@ -659,7 +680,6 @@ static ngx_int_t ngx_http_healthcheck_init(ngx_conf_t *cf) {
659 680 ngx_uint_t i;
660 681
661 682 if (ngx_http_healthchecks_arr->nelts == 0) {
662   - ngx_http_healthchecks = NULL;
663 683 ngx_http_healthchecks_shm = NULL;
664 684 return NGX_OK;
665 685 }
@@ -678,7 +698,6 @@ static ngx_int_t ngx_http_healthcheck_init(ngx_conf_t *cf) {
678 698 }
679 699 shm_zone->init = ngx_http_healthcheck_init_zone;
680 700
681   - ngx_http_healthchecks = ngx_http_healthchecks_arr->elts;
682 701 for (i=0; i<ngx_http_healthchecks_arr->nelts; i++) {
683 702 // I'm not sure what 'temp' means.... when is it removed?
684 703 ngx_http_healthchecks[i].read_buffer = ngx_create_temp_buf(cf->pool,
@@ -790,6 +809,8 @@ ngx_buf_t* ngx_http_healthcheck_buf_append(ngx_buf_t *dst, ngx_buf_t *src,
790 809 ngx_memcpy(new_buf->last, dst->pos, (dst->last - dst->pos));
791 810 new_buf->last += (dst->last - dst->pos);
792 811 // TODO: I don't think there's a way to uncreate the dst buffer (??)
  812 + // Should be ok because these are small and cleared at the end of
  813 + // the status request
793 814 dst = new_buf;
794 815 }
795 816 ngx_memcpy(dst->last, src->pos, (src->last - src->pos));
@@ -1042,3 +1063,5 @@ static char* ngx_http_set_healthcheck_status(ngx_conf_t *cf, ngx_command_t *cmd,
1042 1063
1043 1064 return NGX_CONF_OK;
1044 1065 }
  1066 +
  1067 +#undef ngx_http_healthchecks

0 comments on commit 81da231

Please sign in to comment.
Something went wrong with that request. Please try again.