From 70355145a03ba0671546933c8b97233b476661ff Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 14 Jun 2018 14:49:53 -0400 Subject: [PATCH] fix race condition when inserting a blob to the database --- CHANGELOG.md | 2 +- lbrynet/database/storage.py | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index beb02baad..dda8fb000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ at anytime. ### Fixed * fixed token validation error when the dht node has just been started (https://github.com/lbryio/lbry/issues/1248) - * + * fixed a race condition when inserting a blob into the database (https://github.com/lbryio/lbry/issues/1129) ### Deprecated * diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index 8789f43df..5ac07d6e4 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -226,12 +226,9 @@ class SQLiteStorage(object): @defer.inlineCallbacks def add_known_blob(self, blob_hash, length): - status = yield self.get_blob_status(blob_hash) - if status is None: - status = "pending" - yield self.db.runOperation("insert into blob values (?, ?, ?, ?, ?, ?, ?)", - (blob_hash, length, 0, 0, status, 0, 0)) - defer.returnValue(status) + yield self.db.runOperation( + "insert or ignore into blob values (?, ?, ?, ?, ?, ?, ?)", (blob_hash, length, 0, 0, "pending", 0, 0) + ) def should_announce(self, blob_hash): return self.run_and_return_one_or_none(