Close TCP Connection Using web resource.Resource
Hi, We are struggling to close a TCP connection using web resource.Resource (the TR69 SOAP spec. mandates that we close the connection when we are done). Our site is served in a TCP reactor & uses the NOT_DONE_YET variable in the def render_POST method. We close the render_POST with a request.write('data') & a request.finish() but the connection stays open, stub code below. We are not sure if it is the fact that we are using chunked encoding or if this is a bug? Please assist. Warm Regards, Michael Toop def render_POST(self,request): ...do stuff d = getSoapText(request) d.addCallback(request.write) d.addCallback(request.close()) return server.NOT_DONE_YET
On Thu, May 7, 2009 at 2:05 PM, Michael Toop <michaelt@voxtelecom.co.za> wrote:
Hi,
We are struggling to close a TCP connection using web resource.Resource (the TR69 SOAP spec. mandates that we close the connection when we are done).
Our site is served in a TCP reactor & uses the NOT_DONE_YET variable in the def render_POST method. We close the render_POST with a request.write('data') & a request.finish() but the connection stays open, stub code below.
We are not sure if it is the fact that we are using chunked encoding or if this is a bug?
Please assist.
Warm Regards,
Michael Toop
def render_POST(self,request): ...do stuff d = getSoapText(request) d.addCallback(request.write) d.addCallback(request.close()) return server.NOT_DONE_YET
I'm guessing it was a typo above and should be something like: d.addCallback(lambda ign: request.finish()) Also, I don't think request.finish necessarily entails closing the connection as this depends upon whether or the channel is persistent via keep-alive. I think the rules for connection persistence in twisted.web are: HTTP 1.0: non-persistent HTTP 1.1 and "Connection: close" in request headers: non-persistent HTTP 1.1 and "Connection: close" NOT in request headers: persistent -Drew
Hi Drew, Thanks for the feedback. There are no headers in our server that annotate this. Great idea though, I didn't realise that this was an option. What I will try is insert the "Connection: close" header in & see if the client responds with this (hopefully Twisted will then in turn close the connection). FYI here are the headers in current server: Client: HTTP/1.1 Content-Type: text/xml; charset=ISO-8859-1 Host: vvvaacs.co.za User-Agent: Thomson_cwmp-engine/r6.2.W.1 SOAPAction: Transfer-Encoding: chunked Server: HTTP/1.1 200 OK Transfer-Encoding: chunked Date: Thu, 07 May 2009 12:42:00 GMT Content-Type: text/xml; charset=iso-8859-1 Server: TwistedWeb/8.2.0 Thanks, Michael ________________________________ From: twisted-web-bounces@twistedmatrix.com on behalf of Drew Smathers Sent: Thu 5/7/2009 08:47 PM To: Twisted Web World Subject: Re: [Twisted-web] Close TCP Connection Using web resource.Resource On Thu, May 7, 2009 at 2:05 PM, Michael Toop <michaelt@voxtelecom.co.za> wrote:
Hi,
We are struggling to close a TCP connection using web resource.Resource (the TR69 SOAP spec. mandates that we close the connection when we are done).
Our site is served in a TCP reactor & uses the NOT_DONE_YET variable in the def render_POST method. We close the render_POST with a request.write('data') & a request.finish() but the connection stays open, stub code below.
We are not sure if it is the fact that we are using chunked encoding or if this is a bug?
Please assist.
Warm Regards,
Michael Toop
def render_POST(self,request): ...do stuff d = getSoapText(request) d.addCallback(request.write) d.addCallback(request.close()) return server.NOT_DONE_YET
I'm guessing it was a typo above and should be something like: d.addCallback(lambda ign: request.finish()) Also, I don't think request.finish necessarily entails closing the connection as this depends upon whether or the channel is persistent via keep-alive. I think the rules for connection persistence in twisted.web are: HTTP 1.0: non-persistent HTTP 1.1 and "Connection: close" in request headers: non-persistent HTTP 1.1 and "Connection: close" NOT in request headers: persistent -Drew _______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Thu, May 7, 2009 at 3:22 PM, Michael Toop <michaelt@voxtelecom.co.za> wrote:
Hi Drew,
Thanks for the feedback.
There are no headers in our server that annotate this. Great idea though, I didn't realise that this was an option. What I will try is insert the "Connection: close" header in & see if the client responds with this (hopefully Twisted will then in turn close the connection).
FYI here are the headers in current server:
Client: HTTP/1.1 Content-Type: text/xml; charset=ISO-8859-1 Host: vvvaacs.co.za User-Agent: Thomson_cwmp-engine/r6.2.W.1 SOAPAction: Transfer-Encoding: chunked
Server: HTTP/1.1 200 OK Transfer-Encoding: chunked Date: Thu, 07 May 2009 12:42:00 GMT Content-Type: text/xml; charset=iso-8859-1 Server: TwistedWeb/8.2.0
Thanks,
Michael
Hi Michael, It might be easier to just force the channel to be non-persistent before calling finish() vs. trying to inject request headers: request.channel.persistent = 0 request.finish() -Drew
participants (2)
-
Drew Smathers
-
Michael Toop