joeyates / imap-backup

Backup and Migrate IMAP Email Accounts
MIT License
1.33k stars 74 forks source link

Connection reset by peer #117

Closed kisst closed 2 years ago

kisst commented 2 years ago

I get the bellow error over and over again, but if I start it again it works fine.

S: * OK [CLOSED] Previous mailbox closed.
S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
S: * OK [PERMANENTFLAGS ()] Read-only mailbox.
S: * 1301 EXISTS
S: * 0 RECENT
S: * OK [UIDVALIDITY 1604219053] UIDs valid
S: * OK [UIDNEXT 1302] Predicted next UID
S: RUBY0140 OK [READ-ONLY] Examine completed (0.002 + 0.027 + 0.027 secs).
C: RUBY0141 UID FETCH 489 (BODY[])
Traceback (most recent call last):
        5: from /usr/lib/ruby/2.7.0/net/imap.rb:1121:in `block in initialize'
        4: from /usr/lib/ruby/2.7.0/net/imap.rb:1148:in `receive_responses'
        3: from /usr/lib/ruby/2.7.0/net/imap.rb:1233:in `get_response'
        2: from /usr/lib/ruby/2.7.0/openssl/buffering.rb:207:in `gets'
        1: from /usr/lib/ruby/2.7.0/openssl/buffering.rb:57:in `fill_rbuff'
/usr/lib/ruby/2.7.0/openssl/buffering.rb:57:in `sysread': Connection reset by peer (Errno::ECONNRESET)
joeyates commented 2 years ago

Hi @kisst

Thanks for opening the issue.

I have created the branch 'feature/handle-conn-reset-errors-on-fetch' which should handle this error. If possible, could you try it out? I will include it in the forthcoming release (version 6.0.0), but that may take a while.

kisst commented 2 years ago

I'm pretty much ruby virgin, installed with simple gem install if you can at least point me to the relevant how-to, then more then happy to test it.

joeyates commented 2 years ago

@kisst, try this:

gem uninstall imap-backup # To uninstall the current version
git clone https://github.com/joeyates/imap-backup.git
cd imap-backup/
git checkout --track -b feature/handle-conn-reset-errors-on-fetch origin/feature/handle-conn-reset-errors-on-fetch
gem build imap-backup.gemspec
sudo gem install imap-backup-*.gem

You may not need the sudo on that gem install - it depends on how you installed Ruby.

Let me know how it goes.

kisst commented 2 years ago

Thanks that was more detailed and precise then expected, easy to follow and yes I needed sudo for both the 1st command (uninstall) and the last (install) again.

Here is the next error:

S: * OK [UIDVALIDITY 1604219053] UIDs valid
S: * OK [UIDNEXT 1302] Predicted next UID
S: RUBY0152 OK [READ-ONLY] Examine completed (0.002 + 0.000 + 0.001 secs).
C: RUBY0153 UID FETCH 489 (BODY[])
D, [2022-03-25T11:45:50.677500 #953983] DEBUG -- : Connection reset by peer, attempt 1 of 10
Traceback (most recent call last):
        41: from /usr/local/bin/imap-backup:23:in `<main>'
        40: from /usr/local/bin/imap-backup:23:in `load'
        39: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/bin/imap-backup:13:in `<top (required)>'
        38: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/logger.rb:29:in `sanitize_stderr'
        37: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/bin/imap-backup:14:in `block in <top (required)>'
        36: from /var/lib/gems/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        35: from /var/lib/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        34: from /var/lib/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        33: from /var/lib/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        32: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli.rb:46:in `backup'
        31: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli/backup.rb:15:in `run'
        30: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli/helpers.rb:29:in `each_connection'
        29: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli/accounts.rb:16:in `each'
        28: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli/accounts.rb:16:in `each'
        27: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/cli/helpers.rb:30:in `block in each_connection'
        26: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/connection.rb:66:in `run_backup'
        25: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/connection.rb:146:in `each_folder'
        24: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/connection.rb:146:in `each'
        23: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/connection.rb:148:in `block in each_folder'
        22: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/connection.rb:74:in `block in run_backup'
        21: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/downloader.rb:19:in `run'
        20: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/downloader.rb:19:in `with_index'
        19: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/downloader.rb:19:in `each_slice'
        18: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/downloader.rb:19:in `each'
        17: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/downloader.rb:20:in `block in run'
        16: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/folder.rb:74:in `fetch_multi'
        15: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/retry_on_error.rb:4:in `retry_on_error'
        14: from /var/lib/gems/2.7.0/gems/imap-backup-6.0.0.rc2/lib/imap/backup/account/folder.rb:75:in `block in fetch_multi'
        13: from /usr/lib/ruby/2.7.0/forwardable.rb:235:in `uid_fetch'
        12: from /usr/lib/ruby/2.7.0/net/imap.rb:823:in `uid_fetch'
        11: from /usr/lib/ruby/2.7.0/net/imap.rb:1439:in `fetch_internal'
        10: from /usr/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
         9: from /usr/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
         8: from /usr/lib/ruby/2.7.0/net/imap.rb:1444:in `block in fetch_internal'
         7: from /usr/lib/ruby/2.7.0/net/imap.rb:1258:in `send_command'
         6: from /usr/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
         5: from /usr/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
         4: from /usr/lib/ruby/2.7.0/net/imap.rb:1263:in `block in send_command'
         3: from /usr/lib/ruby/2.7.0/net/imap.rb:1291:in `put_string'
         2: from /usr/lib/ruby/2.7.0/openssl/buffering.rb:421:in `print'
         1: from /usr/lib/ruby/2.7.0/openssl/buffering.rb:322:in `do_write'
/usr/lib/ruby/2.7.0/openssl/buffering.rb:322:in `syswrite': closed stream (IOError)

And again running imap-backup one more time , will reconnect just fine, although, I'm starting to have a feeling that it's not related, because after processing some, it hangs again, seemingly at the same point, same folder same ID presuming that 489 is some kind of ID, and not status code, then at the same point.

kisst commented 2 years ago

Can't really explain it but... what I observed is: If I leave the config for folders empty and let it do all, then it stuck on it, but if I set the folder to one which it stuck on without folders config section, then the replication works just fine.

Something like this: 1) without folders config, run backup, then stuck on X 2) same config restart, stuck same folder X again, and again 3) Set folders to include only folder X, sync started without an issue. 4) Wait for the sync to complete, remove folder config, run again works fine.

kisst commented 2 years ago

Is there any way to get more debug info out of the tool, I got one last folder where even the trick above does not work.

joeyates commented 2 years ago

Hi @kisst

I've added the error you're seeing (IOError) to the list of the ones that are handled.

If you go back to your clone of the imap-backup code and do a git pull, followed by a reinstall (as per instructions above), things may progress a bit.

Let me know if things improve.