Nginx thread pool is not working in 1.14 in custom module

isolomka nginx-forum at
Wed May 23 13:08:08 UTC 2018

Thanks for the response.
The main issue is that now request is closed before actual task is done in
thread pool.
How can I avoid that?
It worked fine before the upgrade. 
What is correct thread pool usage in custom module in 1.14?

Here is my request handler for reference:
static ngx_int_t ngx_http_thread_handler(ngx_http_request_t* r)
  // Add handler (blocking handler)
  task->handler = ngx_http_cgpi_task_handler;
  // Init event
  task-> = taskCtx;
  task->event.handler = ngx_http_cgpi_task_done_cb;

  // Try to get the pool to put task
  ngx_thread_pool_t* tp = clcf->thread_pool;

  if (tp == NULL)
    // Create pool if not exists
    if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) !=
      ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"ngx_http_complex_value \"%V\" failed", &name);
      return NGX_ERROR;
    tp = ngx_thread_pool_get((ngx_cycle_t* ) ngx_cycle, &name);
    if (tp == NULL)
      ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "thread pool \"%V\"
not found", &name);
      return NGX_ERROR;

  // Put the task into thread pool
  if (ngx_thread_task_post(tp, task) != NGX_OK)
    return NGX_ERROR;
  // Make the request blocked
  r->aio = 1;

  return NGX_AGAIN;

Posted at Nginx Forum:,279917,279920#msg-279920

More information about the nginx mailing list