Frank, Thank you for your patch.
I made another patch several minutes ago.
evhttp_request->userdone is used to indicate there is data being sending by
the client. I suppose it is only useful for chunk encoding response. So I
revert the meaning from userdone to user_working and mark the flag only when
chunk encoding is started. IMHO, this should fix this issue. Could the
maintainers take a look at it? Thank you!
This patch is against libevent-1.4.14b.
diff --git a/evhttp.h b/evhttp.h
index 7ddf720..77ff781 100644
--- a/evhttp.h
+++ b/evhttp.h
@@ -222,7 +222,7 @@ struct {
struct evbuffer *input_buffer; /* read data */
ev_int64_t ntoread;
int chunked:1, /* a chunked request */
- userdone:1; /* the user has sent all data */
+ user_working:1; /* the user is sending the data */
struct evbuffer *output_buffer; /* outgoing post or data */
diff --git a/http.c b/http.c
index efcec40..aaaa6d6 100644
--- a/http.c
+++ b/http.c
@@ -610,8 +610,8 @@ evhttp_connection_incoming_fail(struct evhttp_request
*req,
* the request is still being used for sending, we
* need to disassociated it from the connection here.
*/
- if (!req->userdone) {
- /* remove it so that it will not be freed */
+ if (req->user_working) {
+ /* remove it so that it will not be freed*/
TAILQ_REMOVE(&req->evcon->requests, req, next);
/* indicate that this request no longer has a
* connection object
@@ -1942,7 +1942,7 @@ evhttp_send(struct evhttp_request *req, struct
evbuffer *databuf)
assert(TAILQ_FIRST(&evcon->requests) == req);
/* we expect no more calls form the user on this request */
- req->userdone = 1;
+ req->user_working = 0;
/* xxx: not sure if we really should expose the data buffer this way
*/
if (databuf != NULL)
@@ -1967,6 +1967,8 @@ void
evhttp_send_reply_start(struct evhttp_request *req, int code,
const char *reason)
{
+ /* mark the user is sending the request */
+ req->user_working = 1;
evhttp_response_code(req, code, reason);
if (req->major == 1 && req->minor == 1) {
/* use chunked encoding for HTTP/1.1 */
@@ -2008,7 +2010,7 @@ evhttp_send_reply_end(struct evhttp_request *req)
}
/* we expect no more calls form the user on this request */
- req->userdone = 1;
+ req->user_working = 0;
if (req->chunked) {
evbuffer_add(req->evcon->output_buffer, "0\r\n\r\n", 5);
best regards,
hanzhu
On Mon, Jun 28, 2010 at 7:32 PM, Frank Denis <[email protected]> wrote:
> Le Mon, Jun 28, 2010 at 07:21:21PM +0800, Zhu Han ecrivait :
> > I observed the same problem in my environment. I took some time to trace
> the
> > cause. Seems like it's really a bug. Does anybody help me verify it and
> > give a possible fix?
>
> This fixes it for me, although it's probably not the right way to fix
> this :
>
> diff -ur /tmp/a/http.c /tmp/b/http.c
> --- /tmp/a/http.c 2010-06-28 13:29:03.000000000 +0200
> +++ /tmp/b/http.c 2010-06-13 11:41:49.000000000 +0200
> @@ -557,7 +557,9 @@
> */
> if (!req->userdone) {
> /* remove it so that it will not be freed */
> - TAILQ_REMOVE(&req->evcon->requests, req, next);
> + if (req->evcon->http_server == NULL) {
> + TAILQ_REMOVE(&req->evcon->requests, req,
> next);
> + }
> /* indicate that this request no longer has a
> * connection object
> */
>
> --
> Frank Denis - j [at] pureftpd.org - http://00f.net
> _______________________________________________
> Libevent-users mailing list
> [email protected]
> http://lists.monkey.org:8080/listinfo/libevent-users
>
diff --git a/evhttp.h b/evhttp.h
index 7ddf720..77ff781 100644
--- a/evhttp.h
+++ b/evhttp.h
@@ -222,7 +222,7 @@ struct {
struct evbuffer *input_buffer; /* read data */
ev_int64_t ntoread;
int chunked:1, /* a chunked request */
- userdone:1; /* the user has sent all data */
+ user_working:1; /* the user is sending the data */
struct evbuffer *output_buffer; /* outgoing post or data */
diff --git a/http.c b/http.c
index efcec40..aaaa6d6 100644
--- a/http.c
+++ b/http.c
@@ -610,8 +610,8 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
* the request is still being used for sending, we
* need to disassociated it from the connection here.
*/
- if (!req->userdone) {
- /* remove it so that it will not be freed */
+ if (req->user_working) {
+ /* remove it so that it will not be freed*/
TAILQ_REMOVE(&req->evcon->requests, req, next);
/* indicate that this request no longer has a
* connection object
@@ -1942,7 +1942,7 @@ evhttp_send(struct evhttp_request *req, struct evbuffer *databuf)
assert(TAILQ_FIRST(&evcon->requests) == req);
/* we expect no more calls form the user on this request */
- req->userdone = 1;
+ req->user_working = 0;
/* xxx: not sure if we really should expose the data buffer this way */
if (databuf != NULL)
@@ -1967,6 +1967,8 @@ void
evhttp_send_reply_start(struct evhttp_request *req, int code,
const char *reason)
{
+ /* mark the user is sending the request */
+ req->user_working = 1;
evhttp_response_code(req, code, reason);
if (req->major == 1 && req->minor == 1) {
/* use chunked encoding for HTTP/1.1 */
@@ -2008,7 +2010,7 @@ evhttp_send_reply_end(struct evhttp_request *req)
}
/* we expect no more calls form the user on this request */
- req->userdone = 1;
+ req->user_working = 0;
if (req->chunked) {
evbuffer_add(req->evcon->output_buffer, "0\r\n\r\n", 5);
_______________________________________________
Libevent-users mailing list
[email protected]
http://lists.monkey.org:8080/listinfo/libevent-users