Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added some error handling patches and tests

files should not leak disk space on error now.
  • Loading branch information...
commit 0b222fa6c2c852c59dcb19f082cc2fad72533901 1 parent b4ec7d1
BuzzTroll authored
View
9 cumulus/pycb/cbPosixBackend.py
@@ -110,7 +110,7 @@ def __init__(self, data_key, access="r", openIt=True):
self.data_key = data_key
self.blockSize = 1024*512
self.hashValue = None
- self.delete_on_close = True
+ self.delete_on_close = False
self.md5er = hashlib.md5()
if not openIt:
@@ -164,9 +164,6 @@ def set_delete_on_close(self, delete_on_close):
# implement file-like methods
def close(self):
-
- print "closing the file"
-
hashValue = self.get_md5()
if hashValue != None:
try:
@@ -178,10 +175,10 @@ def close(self):
try:
self.file.close()
- except:
+ except Exception, ex:
pycb.log(logging.WARNING, "error closing data object %s %s" % (self.fname, sys.exc_info()[0]), tb=traceback)
if self.delete_on_close:
- print "deleting the file on close"
+ pycb.log(logging.INFO, "deleting the file on close %s" % (self.fname))
self.delete()
View
4 cumulus/pycb/cbRequest.py
@@ -622,8 +622,8 @@ def endGet(self, dataObj):
# it will now be safe to deal with dropped connections
# without having large files left around
dataObj.set_delete_on_close(False)
- dataObj.close()
-
+ # dataObj.close() do no need to close for now. twisted will
+ # do this for us
self.user.put_object(dataObj, self.bucketName, self.objectName)
self.grant_public_permissions(self.bucketName, self.objectName)
View
6 cumulus/pycb/cumulus.py
@@ -167,7 +167,6 @@ def allowed_event(self, request, user, requestId, path):
pycb.log(logging.INFO, "Access granted to ID=%s requestId=%s uri=%s" % (user.get_id(), requestId, request.uri))
cbR = self.request_object_factory(request, user, path, requestId)
- request.notifyFinish().addErrback(self.error_connection_dropped, cbR)
cbR.work()
# http events. all do the same thing
@@ -188,9 +187,6 @@ def render_DELETE(self, request):
self.process_event(request)
return server.NOT_DONE_YET
- def error_connection_dropped(self, cbR):
- print "Error dropped connection"
-
class CumulusHTTPChannel(http.HTTPChannel):
def getAllHeaders(self, req):
@@ -244,6 +240,8 @@ def allHeadersReceived(self):
req.content.close()
# give twisted our own file like object
req.content = pycb.config.bucket.put_object(bucketName, objectName)
+ req.content.set_delete_on_close(True)
+
class CumulusSite(server.Site):
View
34 cumulus/tests/s3cmd/test_connection_drop.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+bucket_name=CumulusTest$RANDOM
+fname=GRP$RANDOM
+s3cmd mb s3://$bucket_name
+
+# make a big enough file
+f=`mktemp`
+dd if=/dev/zero of=$f count=1024 bs=102400
+
+s3cmd put $f s3://$bucket_name/$fname &
+pid=$!
+kill $pid
+rm $f
+
+#s3cmd info s3://$bucket_name/$fname
+#if [ "X$?" == "X0" ]; then
+# echo "ERROR: the file should not be there"
+# exit 1
+#fi
+s3cmd del s3://$bucket_name/$fname
+if [ "X$?" == "X0" ]; then
+ echo "ERROR: the file should not be there"
+ exit 1
+fi
+
+# cleanup
+s3cmd rb s3://$bucket_name
+if [ "X$?" != "X0" ]; then
+ echo "ERROR: delete bucket failed"
+ exit 1
+fi
+
+exit 0
View
40 cumulus/tests/s3cmd/test_drop_gets.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+bucket_name=CumulusTest$RANDOM
+fname=GRP$RANDOM
+s3cmd mb s3://$bucket_name
+
+# make a big enough file
+f=`mktemp`
+dd if=/dev/zero of=$f count=1024 bs=102400
+
+s3cmd put $f s3://$bucket_name/$fname
+if [ "X$?" != "X0" ]; then
+ echo "ERROR: put failed"
+ exit 1
+fi
+
+for i in `seq 1 4`
+do
+ s3cmd --force get s3://$bucket_name/$fname $f &
+ pid=$!
+ echo "s3cmd --force get s3://$bucket_name/$fname $f"
+ sleep 1
+ kill $pid
+ wait
+done
+rm $f
+
+# cleanup
+s3cmd del s3://$bucket_name/$fname
+if [ "X$?" != "X0" ]; then
+ echo "ERROR: did not delete the file"
+ exit 1
+fi
+s3cmd rb s3://$bucket_name
+if [ "X$?" != "X0" ]; then
+ echo "ERROR: delete bucket failed"
+ exit 1
+fi
+
+exit 0
Please sign in to comment.
Something went wrong with that request. Please try again.