Skip to content

Conversation

@mofantor
Copy link

@mofantor mofantor commented Mar 20, 2025

  • 新增ng1.26.3补丁
  • 修改README描述布局(使用markdown)
  • 修复在TCP健康检查方法下,Rise Count不增加的问题

原因分析

在tcp检查下,默认keepalive的请求是1,但http等方式的请求再发送请求后,都会增加connection的requests数量,但在tcp连接方式中没有增加,导致tcp连接不会被关闭

// ngx_http_upstream_check_send_handler
  if (ctx->send.pos == ctx->send.last) {
      ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http check send done.");
      peer->state = NGX_HTTP_CHECK_SEND_DONE;
      c->requests++; // http等检查方式中,增加当前连接的请求数量
  }

//ngx_http_upstream_check_clean_event
        if (c->error == 0 &&
            cf->need_keepalive &&
            (c->requests < ucscf->check_keepalive_requests)) // 这里的c->requests永远是0,没有增加,导致不会进入关闭连接
        {
            c->write->handler = ngx_http_upstream_check_dummy_handler;
            c->read->handler = ngx_http_upstream_check_discard_handler;
        } else {
            ngx_close_connection(c);
            peer->pc.connection = NULL;
        }

所以修复措施就是在tcp连接检查没有问题后,增加一次requsets

// ngx_http_upstream_check_peek_handler
    if (ngx_http_upstream_check_peek_one_byte(c) == NGX_OK) {
        ngx_http_upstream_check_status_update(peer, 1);
        c->requests++;   // 增加requests数量
    } else {
        c->error = 1;
        ngx_http_upstream_check_status_update(peer, 0);
    }

@mofantor
Copy link
Author

mofantor commented Apr 3, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant