         db.query "BEGIN", [], (err, res) =>
             cb err, @
 
+        timeout = setTimeout =>
+            console.error "Danger: lost transaction, rolling back!"
+            timeout = undefined
+            @rollback
+        , LOST_TRANSACTION_TIMEOUT
+        @rmTimeout = ->
+            if timeout
+                clearTimeout timeout
+                timeout = undefined
+
     commit: (cb) ->
         @db.query "COMMIT", [], (err, res) =>
+            @rmTimeout()
             process.nextTick =>
                 dbIsAvailable @db
 

                dbIsAvailable(db)
            cb err, (res?.rows?[0]?)

##
# Wraps the postgres-js transaction with our model operations.
class Transaction


    rollback: (cb) ->
        @db.query "ROLLBACK", [], (err, res) =>
            @rmTimeout()
            process.nextTick =>
                dbIsAvailable @db

