Monitor attachment fd during GET

This prevents download interruption if the LRU closes the associated
database. Will need a tweak when external attachments land in master.

BugzID: 16492


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/f20ccaa1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/f20ccaa1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/f20ccaa1

Branch: refs/heads/import
Commit: f20ccaa1f678526d397e196175d40925de7a44be
Parents: 5168fe0
Author: Robert Newson <[email protected]>
Authored: Sun Jan 20 10:28:35 2013 -0500
Committer: Robert Newson <[email protected]>
Committed: Thu Jan 31 12:51:19 2013 +0000

----------------------------------------------------------------------
 src/chttpd_db.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f20ccaa1/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index c18cdee..0439fdb 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -882,7 +882,9 @@ 
db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
     case [A || A <- Atts, A#att.name == FileName] of
     [] ->
         throw({not_found, "Document is missing attachment"});
-    [#att{type=Type, encoding=Enc, disk_len=DiskLen, att_len=AttLen}=Att] ->
+    [#att{data={Fd,_}, type=Type, encoding=Enc, disk_len=DiskLen, 
att_len=AttLen}=Att] ->
+        Ref = monitor(process, Fd),
+        try
         Etag = chttpd:doc_etag(Doc),
         ReqAcceptsAttEnc = lists:member(
            atom_to_list(Enc),
@@ -963,6 +965,9 @@ 
db_attachment_req(#httpd{method='GET',mochi_req=MochiReq}=Req, Db, DocId, FileNa
                 end
             end
         )
+        after
+            demonitor(Ref)
+        end
     end;
 
 

Reply via email to