Skip to content

Commit cd3e60b

Browse files
committed
fix #7715 -- very low probability of creating a file that can't be opened later
- this causes an error if this were to happen, and then it would just get tried again later and create a new blob (instead of updating an existing one)
1 parent 00ffdf5 commit cd3e60b

File tree

2 files changed

+23
-123
lines changed

2 files changed

+23
-123
lines changed

src/c.js

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/packages/database/postgres-blobs.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ exports.extend_PostgreSQL = (ext) -> class PostgreSQL extends ext
112112
uuid : opts.uuid
113113
cb : (err, _ttl) =>
114114
ttl = _ttl; cb(err)
115+
(cb) =>
116+
# double check that the blob definitely exists and has correct expire
117+
# See discussion at https://github.com/sagemathinc/cocalc/issues/7715
118+
# The problem is that maybe with VERY low probability somehow we extend
119+
# the blob ttl at the same time that we're deleting blobs and the extend
120+
# is too late and does an empty update.
121+
@_query
122+
query : 'SELECT expire FROM blobs'
123+
where : "id = $::UUID" : opts.uuid
124+
cb : (err, x) =>
125+
if err
126+
cb(err)
127+
return
128+
# some consistency checks
129+
rows = x?.rows
130+
if rows.length == 0
131+
cb("blob got removed while saving it")
132+
return
133+
if !opts.ttl and rows[0].expire
134+
cb("blob should have infinite ttl but it has expire set")
135+
return
136+
cb()
137+
115138
], (err) => opts.cb(err, ttl))
116139

117140
# Used internally by save_blob to possibly extend the expire time of a blob.

0 commit comments

Comments
 (0)