Commit aa2e1af6 authored by Amos Latteier's avatar Amos Latteier

Continued to tweak resource freeing code which should reduce leakage when errors occur.

parent 045432f2
......@@ -117,6 +117,7 @@ import DebugLogger
from cStringIO import StringIO
from tempfile import TemporaryFile
import socket, string, os, sys, time
from types import StringType
tz_for_log=compute_timezone_for_log()
......@@ -125,6 +126,8 @@ class PCGIChannel(asynchat.async_chat):
then passing them to ZPublisher. The result is wrapped in a
producer and sent back."""
closed=0
def __init__(self,server,sock,addr):
self.server = server
self.addr = addr
......@@ -177,7 +180,8 @@ class PCGIChannel(asynchat.async_chat):
self.data=StringIO()
DebugLogger.log('B', id(self),
'%s %s' % (self.env['REQUEST_METHOD'], self.env['PATH_INFO']))
'%s %s' % (self.env['REQUEST_METHOD'],
self.env.get('PATH_INFO' ,'/')))
# now read the next size header
self.set_terminator(10)
......@@ -249,31 +253,14 @@ class PCGIChannel(asynchat.async_chat):
def __repr__(self):
return "<PCGIChannel at %x>" % id(self)
def handle_close(self):
def close(self):
self.closed=1
while self.producer_fifo:
p=self.producer_fifo.first()
if p is not None and type(p) != StringType:
p.more() # free up resources held by producer
self.producer_fifo.pop()
self.close()
def handle_error (self):
(file,fun,line), t, v, tbinfo = compact_traceback()
# sometimes a user repr method will crash.
try:
self_repr = repr (self)
except:
self_repr = '<__repr__ (self) failed for object at %0x>' % id(self)
self.log_info (
'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr,
t,
v,
tbinfo
),
'error'
)
self.handle_close()
asyncore.dispatcher.close(self)
class PCGIServer(asyncore.dispatcher):
......@@ -434,15 +421,13 @@ class PCGIPipe:
self._data.write(text)
def close(self):
if not self._channel.closed:
data=self._data.getvalue()
l=len(data)
DebugLogger.log('A', id(self._channel),
'%s %s' % (self._channel.reply_code, l))
self._channel.push('%010d%s%010d' % (l, data, 0), 0)
self._channel.push(LoggingProducer(self._channel, l, 'log_request'), 0)
self._channel.push(CallbackProducer(
lambda t=('E', id(self._channel)): apply(DebugLogger.log,t)))
......
......@@ -117,6 +117,7 @@ import DebugLogger
from cStringIO import StringIO
from tempfile import TemporaryFile
import socket, string, os, sys, time
from types import StringType
tz_for_log=compute_timezone_for_log()
......@@ -125,6 +126,8 @@ class PCGIChannel(asynchat.async_chat):
then passing them to ZPublisher. The result is wrapped in a
producer and sent back."""
closed=0
def __init__(self,server,sock,addr):
self.server = server
self.addr = addr
......@@ -177,7 +180,8 @@ class PCGIChannel(asynchat.async_chat):
self.data=StringIO()
DebugLogger.log('B', id(self),
'%s %s' % (self.env['REQUEST_METHOD'], self.env['PATH_INFO']))
'%s %s' % (self.env['REQUEST_METHOD'],
self.env.get('PATH_INFO' ,'/')))
# now read the next size header
self.set_terminator(10)
......@@ -249,31 +253,14 @@ class PCGIChannel(asynchat.async_chat):
def __repr__(self):
return "<PCGIChannel at %x>" % id(self)
def handle_close(self):
def close(self):
self.closed=1
while self.producer_fifo:
p=self.producer_fifo.first()
if p is not None and type(p) != StringType:
p.more() # free up resources held by producer
self.producer_fifo.pop()
self.close()
def handle_error (self):
(file,fun,line), t, v, tbinfo = compact_traceback()
# sometimes a user repr method will crash.
try:
self_repr = repr (self)
except:
self_repr = '<__repr__ (self) failed for object at %0x>' % id(self)
self.log_info (
'uncaptured python exception, closing channel %s (%s:%s %s)' % (
self_repr,
t,
v,
tbinfo
),
'error'
)
self.handle_close()
asyncore.dispatcher.close(self)
class PCGIServer(asyncore.dispatcher):
......@@ -434,15 +421,13 @@ class PCGIPipe:
self._data.write(text)
def close(self):
if not self._channel.closed:
data=self._data.getvalue()
l=len(data)
DebugLogger.log('A', id(self._channel),
'%s %s' % (self._channel.reply_code, l))
self._channel.push('%010d%s%010d' % (l, data, 0), 0)
self._channel.push(LoggingProducer(self._channel, l, 'log_request'), 0)
self._channel.push(CallbackProducer(
lambda t=('E', id(self._channel)): apply(DebugLogger.log,t)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment