Skip to content

fix: reconnect to DB after long backup upload in Google Drive integra…#18

Open
kaulith wants to merge 1 commit into
frappe:developfrom
kaulith:fix-google-drive-backup-stale-db-connection
Open

fix: reconnect to DB after long backup upload in Google Drive integra…#18
kaulith wants to merge 1 commit into
frappe:developfrom
kaulith:fix-google-drive-backup-stale-db-connection

Conversation

@kaulith

@kaulith kaulith commented Mar 15, 2026

Copy link
Copy Markdown

Closes #17

Problem

upload_system_backup_to_google_drive() runs mysqldump as a subprocess and uploads large files to Google Drive. Both operations take significant time with zero DB activity.

MySQL's wait_timeout kills the idle connection.

When the function reaches
frappe.db.set_single_value("Google Drive", "last_backup_on", ...),
the write fails on the dead connection.

This causes last_backup_on to never update even though backups reach Google Drive successfully.

Fix

Wrap the set_single_value call in a try/except that reconnects on failure:

try:
    frappe.db.set_single_value("Google Drive", "last_backup_on", frappe.utils.now_datetime())
except Exception:
    frappe.db.connect()
    frappe.db.set_single_value("Google Drive", "last_backup_on", frappe.utils.now_datetime())

Testing

Tested with a 4.4 GB database backup file.

Without the fix, the RQ job fails with InterfaceError(0, '').

With the fix, last_backup_on updates correctly after a 51-minute job (well beyond MySQL's 600s/1500 wait_timeout).

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.

Google Drive backup: last_backup_on never updates due to stale DB connection after long upload

1 participant