Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/malformed json lock race condition #106

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions A2rchi/interfaces/chat_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def terms(self):
return render_template('terms.html')

def like(self):
self.chat.lock.acquire()
try:
# Get the JSON data from the request body
data = request.json
Expand All @@ -231,11 +232,16 @@ def like(self):
response = {'message': 'Liked', 'content': chat_content}
return jsonify(response), 200


except Exception as e:
return jsonify({'error': str(e)}), 500


# According to the Python documentation: https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions
# this will still execute, before the function returns in the try or except block.
finally:
self.chat.lock.release()

def dislike(self):
self.chat.lock.acquire()
try:
# Get the JSON data from the request body
data = request.json
Expand Down Expand Up @@ -263,6 +269,10 @@ def dislike(self):
response = {'message': 'Disliked', 'content': chat_content}
return jsonify(response), 200


except Exception as e:
return jsonify({'error': str(e)}), 500

# According to the Python documentation: https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions
# this will still execute, before the function returns in the try or except block.
finally:
self.chat.lock.release()
3 changes: 3 additions & 0 deletions A2rchi/utils/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def _add_to_vectorstore(self, collection, files_to_add, sources={}):
time_identifier = hashlib.md5()
time_identifier.update(str(time.time()).encode('utf-8'))
time_hash = str(int(identifier.hexdigest(),16))[0:6]
while str(filehash) + str(chunk_hash) + str(time_hash) in ids:
print("INFO: Found conflict with hash: " + str(filehash) + str(chunk_hash) + str(time_hash) + ". Trying again")
time_hash = str(int(time_hash) + 1)
ids.append(str(filehash) + str(chunk_hash) + str(time_hash))

print("Ids: ",ids)
Expand Down