joeyates / imap-backup

Backup and Migrate IMAP Email Accounts
MIT License
1.37k stars 75 forks source link

Flag refresher undefined method `each' for nil:NilClass #204

Closed jordancrawfordnz closed 3 months ago

jordancrawfordnz commented 3 months ago

Environment

I use imap-backup to backup my iCloud email. I run the software in Docker on my Synology NAS - the Docker image I use is https://github.com/theohbrothers/docker-imap-backup.

A weekly cron job runs a script which pulls the latest image and kicks off the backup.

Version

This issue has started happening on version v15.0.1

About the issue

Stack trace:

E, [2024-06-09T10:05:18.284431 #1] ERROR -- : Backup for account 'redacted@me.com' failed with error undefined method `each' for nil:NilClass
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/flag_refresher.rb:31:in `refresh_block'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/flag_refresher.rb:20:in `block in run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/flag_refresher.rb:19:in `each'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/flag_refresher.rb:19:in `each_slice'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/flag_refresher.rb:19:in `run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/folder_backup.rb:34:in `block in run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/delayed_metadata_serializer.rb:36:in `block (2 levels) in transaction'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/mbox.rb:27:in `block in transaction'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/transaction.rb:26:in `begin'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/mbox.rb:26:in `transaction'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/delayed_metadata_serializer.rb:35:in `block in transaction'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/transaction.rb:26:in `begin'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/serializer/delayed_metadata_serializer.rb:34:in `transaction'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/folder_backup.rb:32:in `run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/backup.rb:35:in `block in run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/backup_folders.rb:42:in `block in each'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/backup_folders.rb:42:in `each'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/backup_folders.rb:42:in `each'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/account/backup.rb:34:in `run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/cli/backup.rb:36:in `block in run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/cli/backup.rb:34:in `each'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/cli/backup.rb:34:in `run'
/usr/local/bundle/gems/imap-backup-15.0.1/lib/imap/backup/cli.rb:94:in `backup'

See the full redacted sync log -

imap-backup-redacted-error.txt

Relevant code: https://github.com/joeyates/imap-backup/blob/main/lib/imap/backup/flag_refresher.rb#L31 uids_and_flags appears to have been nil, causing the error.

This error happened 5 minutes into the job and fairly soon after Folder 'Trash' caused a NoMethodError which happens regularly due to Apple Mail servers so may not be particularly relevant. The backup tends to run for about 50 minutes most weeks.

I kicked off a manual backup and confirmed it happened again at the same point.

Please let me know if there's anything else I can do to help debug the issue.

jordancrawfordnz commented 3 months ago

I wondered if this related to Ruby 3 compatibility, but it seems like docker-imap-backup uses Ruby 3.2 - https://github.com/theohbrothers/docker-imap-backup/blob/master/generate/templates/Dockerfile.ps1 - so I don't think that's relevant.

jordancrawfordnz commented 3 months ago

I downgraded my version and confirmed the backup job ran successfully on 14.6.1.

If I get a chance later I'll try a run on another machine with the same config and email account to see if I can reproduce the issue.

joeyates commented 3 months ago

Hi @jordancrawfordnz

Thanks for opening this issue.

I'll get a fix out asap.

BTW: the "official" container image for this project is ghcr.io/joeyates/imap-backup:latest

joeyates commented 3 months ago

I've published v15.0.2 with a fix for this.

jordancrawfordnz commented 3 months ago

Excellent - thank you, the new version is working now. I didn't realise there was an official container image - maybe I missed that when I originally set it up, I'll switch over to that - thanks for the tip!