diff options
author | Mark Sapiro <mark@msapiro.net> | 2008-02-14 08:53:52 -0800 |
---|---|---|
committer | Mark Sapiro <mark@msapiro.net> | 2008-02-14 08:53:52 -0800 |
commit | 2e5d927a50e5b3c7006497416506fa9fa8f8d33a (patch) | |
tree | 66e2be47e04e1bf1ff5fab83292fefdcd098877e /Mailman/Queue/Switchboard.py | |
parent | f05065b0111adaa311ab909c29c1b93bd34451fc (diff) | |
download | mailman2-2e5d927a50e5b3c7006497416506fa9fa8f8d33a.tar.gz mailman2-2e5d927a50e5b3c7006497416506fa9fa8f8d33a.tar.xz mailman2-2e5d927a50e5b3c7006497416506fa9fa8f8d33a.zip |
Switchboard.py - Added code to catch exceptions thrown in unpickling .bak
files and preserve the file. This occurred when dequeue
of a large entry threw MemoryError, the runner died and
restarted, and then unpickling the .bak threw another
MemoryError.
Diffstat (limited to '')
-rw-r--r-- | Mailman/Queue/Switchboard.py | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/Mailman/Queue/Switchboard.py b/Mailman/Queue/Switchboard.py index a774c580..7a0b770f 100644 --- a/Mailman/Queue/Switchboard.py +++ b/Mailman/Queue/Switchboard.py @@ -223,24 +223,33 @@ class Switchboard: dst = os.path.join(self.__whichq, filebase + '.pck') fp = open(src, 'rb+') try: - msg = cPickle.load(fp) - data_pos = fp.tell() - data = cPickle.load(fp) - data['_bak_count'] = data.setdefault('_bak_count', 0) + 1 - fp.seek(data_pos) - if data.get('_parsemsg'): - protocol = 0 + try: + msg = cPickle.load(fp) + data_pos = fp.tell() + data = cPickle.load(fp) + except Exception, s: + # If unpickling throws any exception, just log and + # preserve this entry + syslog('error', 'Unpickling .bak exception: %s\n' + + 'preserving file: %s', s, filebase) + self.finish(filebase, preserve=True) else: - protocol = 1 - cPickle.dump(data, fp, protocol) - fp.truncate() - fp.flush() - os.fsync(fp.fileno()) + data['_bak_count'] = data.setdefault('_bak_count', 0) + 1 + fp.seek(data_pos) + if data.get('_parsemsg'): + protocol = 0 + else: + protocol = 1 + cPickle.dump(data, fp, protocol) + fp.truncate() + fp.flush() + os.fsync(fp.fileno()) + if data['_bak_count'] >= MAX_BAK_COUNT: + syslog('error', + '.bak file max count, preserving file: %s', + filebase) + self.finish(filebase, preserve=True) + else: + os.rename(src, dst) finally: fp.close() - if data['_bak_count'] >= MAX_BAK_COUNT: - syslog('error', '.bak file max count, preserving file: %s', - filebase) - self.finish(filebase, preserve=True) - else: - os.rename(src, dst) |