From 89e58fa474c9a1ef33f8ea904f5d1029df942f1e Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Wed, 5 Jun 2019 10:35:47 +0200 Subject: [PATCH] Improve iterator support for Python req.response(). If the connection on which we are about to send the response was marked as disconnecting, do not go ahead and hook into the disconnect callback (it will never be called, it is already disconnecting). Instead just return, the connection will be removed anyway. --- src/python.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/python.c b/src/python.c index 4ed0b7d..49c2245 100644 --- a/src/python.c +++ b/src/python.c @@ -3159,11 +3159,14 @@ pyhttp_response(struct pyhttp_request *pyreq, PyObject *args) } else if (obj == Py_None) { http_response(pyreq->req, status, NULL, 0); } else { + c = pyreq->req->owner; + if (c->state == CONN_STATE_DISCONNECTING) { + Py_RETURN_FALSE; + } + if ((iterator = PyObject_GetIter(obj)) == NULL) return (NULL); - c = pyreq->req->owner; - iterobj = kore_pool_get(&iterobj_pool); iterobj->iterator = iterator; iterobj->connection = c;