Merge pull request #1299 from slootjes/master

Prevent possible download counter race condition
This commit is contained in:
Danny Coates 2019-04-19 10:37:58 -07:00 committed by GitHub
commit 147ed4c736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -34,7 +34,7 @@ module.exports = async function(req, res) {
if (dl >= dlimit) { if (dl >= dlimit) {
await storage.del(id); await storage.del(id);
} else { } else {
await storage.setField(id, 'dl', dl); await storage.incrementField(id, 'dl');
} }
} catch (e) { } catch (e) {
log.info('StorageError:', id); log.info('StorageError:', id);

View file

@ -62,6 +62,10 @@ class DB {
this.redis.hset(id, key, value); this.redis.hset(id, key, value);
} }
incrementField(id, key, increment = 1) {
this.redis.hincrby(id, key, increment);
}
async del(id) { async del(id) {
const filePath = await this.getPrefixedId(id); const filePath = await this.getPrefixedId(id);
this.storage.del(filePath); this.storage.del(filePath);