Libunit: fixing racing condition in request struct recycling.

The issue occurred under highly concurrent request load in Go applications.
Such applications are multi-threaded but use a single libunit context; any
thread-safe code in the libunit context is only required for Go applications.

As a result of improper request state reset, the recycled request structure was
recovered in the released state, so further operations with this request
resulted in 'response already sent' warnings.  However, the actual response was
never delivered to the router and the client.
This commit is contained in:
Max Romanov
2020-11-18 22:33:53 +03:00
parent 0ec69aa46e
commit d26afcb481

View File

@@ -1751,6 +1751,8 @@ nxt_unit_request_info_release(nxt_unit_request_info_t *req)
req->response_port = NULL;
}
req_impl->state = NXT_UNIT_RS_RELEASED;
pthread_mutex_lock(&ctx_impl->mutex);
nxt_queue_remove(&req_impl->link);
@@ -1758,8 +1760,6 @@ nxt_unit_request_info_release(nxt_unit_request_info_t *req)
nxt_queue_insert_tail(&ctx_impl->free_req, &req_impl->link);
pthread_mutex_unlock(&ctx_impl->mutex);
req_impl->state = NXT_UNIT_RS_RELEASED;
}