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

4651 : adding a change to fix database is locked error #4960

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

RADXIshan
Copy link

Made changes in the file cvedb.py to fix the issue 4651

LOGGER.error("Database cursor does not exist")
raise CVEDBError
return cursor
def db_open_and_get_cursor(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the type hint here.

retries = 0
while retries < MAX_RETRIES:
try:
self.connection = sqlite3.connect(self.dbpath, timeout=10) # Extend timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident we should extend the timeout in addition to adding the retry logic, but I could be convinced. What's the thinking behind this change?

if "database is locked" in str(e):
retries += 1
wait_time = RETRY_DELAY * (2 ** retries) # Exponential backoff
print(f"Database locked, retrying in {wait_time:.2f} seconds...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make use of the LOGGER object here instead of a bare print call.

print(f"Database locked, retrying in {wait_time:.2f} seconds...")
time.sleep(wait_time)
else:
raise # Raise other errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this raise and the one right below it, we should use LOGGER.error and raise CVEDBError instead of raising whatever sqlite3 gives us. That will keep the existing error handler logic usable if it's ever needed for something.

while retries < MAX_RETRIES:
try:
self.connection = sqlite3.connect(self.dbpath, timeout=10) # Extend timeout
self.connection.execute("PRAGMA journal_mode=WAL;") # Improve concurrency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to think of side effects this might cause. This will create some extra files on disk next to our database, right? I don't think there would be issues with this change, but I defer to the other maintainers who might be more familiar with the SQLite stuff...

@stvml
Copy link
Contributor

stvml commented Mar 28, 2025

Thanks for working on this, @RADXIshan! I think this could help with the intermittent database issues. Please look over my review comments when you get a chance.

@stvml stvml requested a review from terriko March 28, 2025 18:16
@RADXIshan
Copy link
Author

RADXIshan commented Mar 28, 2025 via email

@RADXIshan RADXIshan requested a review from stvml March 30, 2025 09:27
Copy link
Contributor

@stvml stvml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is almost ready to merge. Please remove the .DS_Store files from your PR, and I'll run CI once those are gone. Thanks!

@RADXIshan
Copy link
Author

I think this is almost ready to merge. Please remove the .DS_Store files from your PR, and I'll run CI once those are gone. Thanks!

I have removed '.DS_Store' from my PR, let me know if any other changes are needed

while retries < MAX_RETRIES:
try:
self.connection = sqlite3.connect(self.dbpath, timeout=10) # Extend timeout for better handling
return self.connection.cursor()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, one last change here... I think we should keep the existing check for if cursor is None before we return the result of this call. Not sure if this error ever happens in the real world, but it's better to preserve logic that we aren't sure about :)

@stvml stvml self-requested a review April 8, 2025 18:24
Copy link
Contributor

@stvml stvml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like syntax errors are causing the tests to fail. You might try running the tests locally before pushing (see here for documentation).

@RADXIshan
Copy link
Author

Looks like syntax errors are causing the tests to fail. You might try running the tests locally before pushing (see here for documentation).

One tab changed the whole indentation of the code and i didnt even realise :), thankss for the check i think now it will work 👍

@stvml
Copy link
Contributor

stvml commented Apr 8, 2025

Please have a look at this section of CONTRIBUTING.md for information about the linters this project uses. Highly recommend using pre-commit to automatically lint your contributions at push time.

@RADXIshan
Copy link
Author

Please have a look at this section of CONTRIBUTING.md for information about the linters this project uses. Highly recommend using pre-commit to automatically lint your contributions at push time.

ok i will go through it , this all is kind of new to me thats why i got confused , thanks for the guidance!

@RADXIshan
Copy link
Author

Please have a look at this section of CONTRIBUTING.md for information about the linters this project uses. Highly recommend using pre-commit to automatically lint your contributions at push time.

I have tried implementing as much as i understood and i think the errors from my end are fixed now , i went through the pre commit command and fixed the errors, it is showing some errors in some files which i have not touched ,like its showing that those files have not gone through much tests, but i fixed everything for my own file , can please check once and thanks a lot for guiding me through everything i really love working with you, lemme know if i am going wrong somewhere and how i can fix that :)

@RADXIshan RADXIshan requested a review from stvml April 8, 2025 20:01
@RADXIshan
Copy link
Author

Screenshot 2025-04-09 at 2 55 28 AM i am not able to fix this can you please help me with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants