From bd424f80f359a0dea4a99ec059ec525380a8b4f6 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Mon, 5 Feb 2001 15:04:32 +0000 Subject: [PATCH] ap_new_connection() returns NULL if an error occurred (prefork MPM and ap_new_connection() were changed last week) I have skipped putting the change into WinNT MPM and mod_proxy. I left a note in the mod_proxy code; for the NT MPM I think I can talk somebody into doing the right thing for me. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87982 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ include/http_connection.h | 1 + modules/proxy/proxy_http.c | 6 ++++++ server/mpm/beos/beos.c | 7 ++++--- server/mpm/dexter/dexter.c | 7 ++++--- server/mpm/experimental/perchild/perchild.c | 7 ++++--- server/mpm/mpmt_beos/mpmt_beos.c | 7 ++++--- server/mpm/mpmt_pthread/mpmt_pthread.c | 7 ++++--- server/mpm/perchild/perchild.c | 7 ++++--- server/mpm/spmt_os2/spmt_os2.c | 7 ++++--- 10 files changed, 39 insertions(+), 21 deletions(-) diff --git a/CHANGES b/CHANGES index 87bdb53501..674fe385af 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Changes with Apache 2.0b1 + *) ap_new_connection() closes the socket and returns NULL if a socket + call fails. Usually this is due to a connection which has been + reset. [Jeff Trawick] + *) Move the Apache version information out of httpd.h and into release.h. This is in preparation for the first tag with the new tag and release system. [Ryan Bloom] diff --git a/include/http_connection.h b/include/http_connection.h index 82c3135e6e..5bff6bc729 100644 --- a/include/http_connection.h +++ b/include/http_connection.h @@ -73,6 +73,7 @@ extern "C" { * @param server The server to create the connection for * @param inout The socket to use for all communication with the client * @param id ID of this connection; unique at any point in time. + * @return new conn_rec, or NULL if the connection has already been reset */ conn_rec *ap_new_connection(apr_pool_t *p, server_rec *server, apr_socket_t *inout, long id); diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index 3e61f2e7b3..68e9837b6a 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -277,6 +277,12 @@ int ap_proxy_http_handler(request_rec *r, char *url, } origin = ap_new_connection(r->pool, r->server, sock, 0); + if (!origin) { + /* the peer reset the connection already; ap_new_connection() + * closed the socket */ + /* XXX somebody that knows what they're doing add an error path */ + } + ap_add_output_filter("CORE", NULL, NULL, origin); clear_connection(r->pool, r->headers_in); /* Strip connection-based headers */ diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index 761e5ab14a..ff7361bc93 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -317,9 +317,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num) } current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } static int32 worker_thread(void * dummy) diff --git a/server/mpm/dexter/dexter.c b/server/mpm/dexter/dexter.c index 7f198e9751..8cd3d2c717 100644 --- a/server/mpm/dexter/dexter.c +++ b/server/mpm/dexter/dexter.c @@ -419,9 +419,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id) SERVER_BUSY_READ, (request_rec *) NULL); current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } static void *worker_thread(void *); diff --git a/server/mpm/experimental/perchild/perchild.c b/server/mpm/experimental/perchild/perchild.c index 10932bc8e0..899e84429a 100644 --- a/server/mpm/experimental/perchild/perchild.c +++ b/server/mpm/experimental/perchild/perchild.c @@ -456,9 +456,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id) } current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } static void *worker_thread(void *); diff --git a/server/mpm/mpmt_beos/mpmt_beos.c b/server/mpm/mpmt_beos/mpmt_beos.c index 616cdb7d56..c758bd1fef 100644 --- a/server/mpm/mpmt_beos/mpmt_beos.c +++ b/server/mpm/mpmt_beos/mpmt_beos.c @@ -300,9 +300,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num, int csd; current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } static int32 worker_thread(void * dummy) diff --git a/server/mpm/mpmt_pthread/mpmt_pthread.c b/server/mpm/mpmt_pthread/mpmt_pthread.c index 368cb1b467..5f707e46f4 100644 --- a/server/mpm/mpmt_pthread/mpmt_pthread.c +++ b/server/mpm/mpmt_pthread/mpmt_pthread.c @@ -410,9 +410,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, int my_child_num, SERVER_BUSY_READ, (request_rec *) NULL); current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } /* Sets workers_may_exit if we received a character on the pipe_of_death */ static void check_pipe_of_death(void) diff --git a/server/mpm/perchild/perchild.c b/server/mpm/perchild/perchild.c index 10932bc8e0..899e84429a 100644 --- a/server/mpm/perchild/perchild.c +++ b/server/mpm/perchild/perchild.c @@ -456,9 +456,10 @@ static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id) } current_conn = ap_new_connection(p, ap_server_conf, sock, conn_id); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } static void *worker_thread(void *); diff --git a/server/mpm/spmt_os2/spmt_os2.c b/server/mpm/spmt_os2/spmt_os2.c index f8a2983e2f..0ed25a025e 100644 --- a/server/mpm/spmt_os2/spmt_os2.c +++ b/server/mpm/spmt_os2/spmt_os2.c @@ -940,9 +940,10 @@ static void child_main(void *child_num_arg) current_conn = ap_new_connection(ptrans, ap_server_conf, csd, THREAD_GLOBAL(child_num)); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } clean_child_exit(0); -- 2.40.0