svn commit: samba r9409 - in branches/SAMBA_4_0/source/web_server: .

tridge at samba.org tridge at samba.org
Sat Aug 20 04:38:36 GMT 2005


Author: tridge
Date: 2005-08-20 04:38:35 +0000 (Sat, 20 Aug 2005)
New Revision: 9409

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9409

Log:
fix a problem that volker noticed with web page timeouts causing smbd
to crash. This is one of the downsides of the fact that the ejs engine
is not event driven, resulting in the rendering of each web page being
'semi-async'. We need to protect the web context from the timeout
processing until we have unwound the stack back to the point that the
'web' variable representing the page rendering logic won't be used any
more.

Modified:
   branches/SAMBA_4_0/source/web_server/http.c
   branches/SAMBA_4_0/source/web_server/web_server.c


Changeset:
Modified: branches/SAMBA_4_0/source/web_server/http.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/http.c	2005-08-20 01:38:31 UTC (rev 9408)
+++ branches/SAMBA_4_0/source/web_server/http.c	2005-08-20 04:38:35 UTC (rev 9409)
@@ -501,6 +501,7 @@
 		return;
 	}
 #endif
+
 	res = espProcessRequest(esp->req, url, buf, &emsg);
 	if (res != 0 && emsg) {
 		http_writeBlock(web, "<pre>", 5);
@@ -866,6 +867,12 @@
 		}
 	}
 
+	if (web->conn == NULL) {
+		/* the connection has been terminated above us, probably
+		   via a timeout */
+		goto internal_error;
+	}
+
 	if (!web->output.output_pending) {
 		http_output_headers(web);
 		EVENT_FD_WRITEABLE(web->conn->event.fde);
@@ -909,7 +916,9 @@
 internal_error:
 	mprSetCtx(esp);
 	talloc_free(esp);
-	http_error(web, 500, "Internal server error");
+	if (web->conn != NULL) {
+		http_error(web, 500, "Internal server error");
+	}
 	mprSetCtx(save_mpr_ctx);
 	ejs_restore_state(ejs_save);
 }

Modified: branches/SAMBA_4_0/source/web_server/web_server.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/web_server.c	2005-08-20 01:38:31 UTC (rev 9408)
+++ branches/SAMBA_4_0/source/web_server/web_server.c	2005-08-20 04:38:35 UTC (rev 9409)
@@ -52,7 +52,11 @@
 			   struct timeval t, void *private)
 {
 	struct websrv_context *web = talloc_get_type(private, struct websrv_context);
-	stream_terminate_connection(web->conn, "websrv_timeout: timed out");
+	struct stream_connection *conn = web->conn;
+	web->conn = NULL;
+	/* TODO: send a message to any running esp context on this connection
+	   to stop running */
+	stream_terminate_connection(conn, "websrv_timeout: timed out");	
 }
 
 /*
@@ -108,7 +112,17 @@
 			web->input.partial.data[web->input.content_length] = 0;
 		}
 		EVENT_FD_NOT_READABLE(web->conn->event.fde);
+
+		/* the reference/unlink code here is quite subtle. It
+		 is needed because the rendering of the web-pages, and
+		 in particular the esp/ejs backend, is semi-async.  So
+		 we could well end up in the connection timeout code
+		 while inside http_process_input(), but we must not
+		 destroy the stack variables being used by that
+		 rendering process when we handle the timeout. */
+		talloc_reference(web->task, web);
 		http_process_input(web);
+		talloc_unlink(web->task, web);
 	}
 	return;
 



More information about the samba-cvs mailing list