Index: server/mpm/event/event.c =================================================================== --- server/mpm/event/event.c (revision 1809259) +++ server/mpm/event/event.c (working copy) @@ -690,24 +690,23 @@ static int start_lingering_close_common(event_conn else { cs->c->sbh = NULL; } - apr_thread_mutex_lock(timeout_mutex); - TO_QUEUE_APPEND(q, cs); cs->pfd.reqevents = ( cs->pub.sense == CONN_SENSE_WANT_WRITE ? APR_POLLOUT : APR_POLLIN) | APR_POLLHUP | APR_POLLERR; cs->pub.sense = CONN_SENSE_DEFAULT; + apr_thread_mutex_lock(timeout_mutex); + TO_QUEUE_APPEND(q, cs); rv = apr_pollset_add(event_pollset, &cs->pfd); - apr_thread_mutex_unlock(timeout_mutex); if (rv != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rv)) { + TO_QUEUE_REMOVE(q, cs); + apr_thread_mutex_unlock(timeout_mutex); ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(03092) "start_lingering_close: apr_pollset_add failure"); - apr_thread_mutex_lock(timeout_mutex); - TO_QUEUE_REMOVE(q, cs); - apr_thread_mutex_unlock(timeout_mutex); apr_socket_close(cs->pfd.desc.s); ap_push_pool(worker_queue_info, cs->p); return 0; } + apr_thread_mutex_unlock(timeout_mutex); return 1; } @@ -974,14 +973,25 @@ read_request: */ cs->queue_timestamp = apr_time_now(); notify_suspend(cs); - apr_thread_mutex_lock(timeout_mutex); - TO_QUEUE_APPEND(cs->sc->wc_q, cs); cs->pfd.reqevents = ( cs->pub.sense == CONN_SENSE_WANT_READ ? APR_POLLIN : APR_POLLOUT) | APR_POLLHUP | APR_POLLERR; cs->pub.sense = CONN_SENSE_DEFAULT; + apr_thread_mutex_lock(timeout_mutex); + TO_QUEUE_APPEND(cs->sc->wc_q, cs); rc = apr_pollset_add(event_pollset, &cs->pfd); - apr_thread_mutex_unlock(timeout_mutex); + if (rc != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rc)) { + TO_QUEUE_REMOVE(cs->sc->wc_q, cs); + apr_thread_mutex_unlock(timeout_mutex); + ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, APLOGNO(03465) + "process_socket: apr_pollset_add failure for " + "write completion"); + apr_socket_close(cs->pfd.desc.s); + ap_push_pool(worker_queue_info, cs->p); + } + else { + apr_thread_mutex_unlock(timeout_mutex); + } return; } else if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted || @@ -1011,19 +1021,24 @@ read_request: */ cs->queue_timestamp = apr_time_now(); notify_suspend(cs); - apr_thread_mutex_lock(timeout_mutex); - TO_QUEUE_APPEND(cs->sc->ka_q, cs); /* Add work to pollset. */ cs->pfd.reqevents = APR_POLLIN; + apr_thread_mutex_lock(timeout_mutex); + TO_QUEUE_APPEND(cs->sc->ka_q, cs); rc = apr_pollset_add(event_pollset, &cs->pfd); - apr_thread_mutex_unlock(timeout_mutex); - - if (rc != APR_SUCCESS) { + if (rc != APR_SUCCESS && !APR_STATUS_IS_EEXIST(rc)) { + TO_QUEUE_REMOVE(cs->sc->ka_q, cs); + apr_thread_mutex_unlock(timeout_mutex); ap_log_error(APLOG_MARK, APLOG_ERR, rc, ap_server_conf, APLOGNO(03093) - "process_socket: apr_pollset_add failure"); - AP_DEBUG_ASSERT(rc == APR_SUCCESS); + "process_socket: apr_pollset_add failure for " + "keep alive"); + apr_socket_close(cs->pfd.desc.s); + ap_push_pool(worker_queue_info, cs->p); } + else { + apr_thread_mutex_unlock(timeout_mutex); + } } else if (cs->pub.state == CONN_STATE_SUSPENDED) { apr_atomic_inc32(&suspended_count); @@ -1274,16 +1289,15 @@ static void process_lingering_close(event_conn_sta } apr_thread_mutex_lock(timeout_mutex); + TO_QUEUE_REMOVE(q, cs); rv = apr_pollset_remove(event_pollset, pfd); - AP_DEBUG_ASSERT(rv == APR_SUCCESS); + apr_thread_mutex_unlock(timeout_mutex); + AP_DEBUG_ASSERT(rv == APR_SUCCESS || APR_STATUS_IS_NOTFOUND(rv)); + TO_QUEUE_ELEM_INIT(cs); rv = apr_socket_close(csd); AP_DEBUG_ASSERT(rv == APR_SUCCESS); - TO_QUEUE_REMOVE(q, cs); - apr_thread_mutex_unlock(timeout_mutex); - TO_QUEUE_ELEM_INIT(cs); - ap_push_pool(worker_queue_info, cs->p); if (dying) ap_queue_interrupt_one(worker_queue); @@ -1514,7 +1528,6 @@ static void * APR_THREAD_FUNC listener_thread(apr_ TO_QUEUE_REMOVE(remove_from_q, cs); rc = apr_pollset_remove(event_pollset, &cs->pfd); apr_thread_mutex_unlock(timeout_mutex); - /* * Some of the pollset backends, like KQueue or Epoll * automagically remove the FD if the socket is closed,