Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

unix: Fix canceling request if it's the only one #669

Closed
wants to merge 1 commit into from

2 participants

@saghul
Collaborator

This is a fix for the following case (which I surprisingly run into): there is a single request in the thread pool (say a getaddrinfo) and it's cancelled before it gets a chance to run. If no other request is put in the thread pool, the work_async will not be sent and thus the done callback will never be called. The fix consists in sending the async in case the cancelled request is the last request.

I don't know if a reliable test case can be written for this, though :-S

/cc @bnoordhuis

@bnoordhuis bnoordhuis referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@bnoordhuis

@saghul Can you test 5ae28c2? Quoting the commit log:

Wake up the event loop with uv_async_send() when a request is cancelled.
Ensures the done_cb is run on the next tick of the event loop.

Not sending a wakeup signal results in the done_cb not getting called until
another request completes, which may be a long time coming when it's the only
request in the queue or when other requests are executing long-running jobs.
@saghul
Collaborator

@bnoordhuis that works :-)

@bnoordhuis bnoordhuis closed this pull request from a commit
@bnoordhuis bnoordhuis unix: ensure done_cb gets called after uv_cancel()
Wake up the event loop with uv_async_send() when a request is cancelled.
Ensures the done_cb is run on the next tick of the event loop.

Not sending a wakeup signal results in the done_cb not getting called until
another request completes, which may be a long time coming when it's the only
request in the queue or when other requests are executing long-running jobs.

Fixes #669.
92a19a1
@bnoordhuis

Thanks for testing, landed in 92a19a1.

@saghul saghul deleted the unknown repository branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 26, 2012
  1. @saghul
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/unix/threadpool.c
View
5 src/unix/threadpool.c
@@ -141,6 +141,7 @@ void uv__work_submit(uv_loop_t* loop,
int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
int cancelled;
+ int wq_empty;
uv_mutex_lock(&mutex);
uv_mutex_lock(&w->loop->wq_mutex);
@@ -149,6 +150,8 @@ int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
if (cancelled)
ngx_queue_remove(&w->wq);
+ wq_empty = ngx_queue_empty(&wq);
+
uv_mutex_unlock(&w->loop->wq_mutex);
uv_mutex_unlock(&mutex);
@@ -158,6 +161,8 @@ int uv__work_cancel(uv_loop_t* loop, uv_req_t* req, struct uv__work* w) {
w->work = uv__cancelled;
uv_mutex_lock(&loop->wq_mutex);
ngx_queue_insert_tail(&loop->wq, &w->wq);
+ if (wq_empty)
+ uv_async_send(&w->loop->wq_async);
uv_mutex_unlock(&loop->wq_mutex);
return 0;
Something went wrong with that request. Please try again.