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

Transaction rollbacks can cause mail loss #117

Open
guettli opened this issue Sep 2, 2016 · 5 comments
Open

Transaction rollbacks can cause mail loss #117

guettli opened this issue Sep 2, 2016 · 5 comments
Labels

Comments

@guettli
Copy link

guettli commented Sep 2, 2016

I want to know if loosing mail can happen.

Maybe like this.

  1. Cron job calls python manage.py getmail
  2. DB transaction starts
  3. Mail gets fetched from pop3 server
  4. Mail gets stored in DB
  5. Mails gets handled by custom signal handler
  6. Mail gets deleted on pop3 server
  7. DB commit, but BANG: One DB constraint complaints and the whole transaction gets rolled back.

This would result in message lost, since the pop3 server has deleted the mail, but the mail was never entered into the DB since the transaction was rolled back.

@ad-m
Copy link
Collaborator

ad-m commented Sep 2, 2016

There is no transaction for each message, unfortunately (see #66), so message was deleted before transaction of message was commited, so data loss is possible IMO. I'm not have the time to work on such a feature, but feel free to submit a PR.

@guettli
Copy link
Author

guettli commented Sep 5, 2016

Django 1.9 has a nice signal: on_commit():
https://docs.djangoproject.com/en/1.10/topics/db/transactions/#django.db.transaction.on_commit

Sometimes you need to perform an action related to the current database transaction, but only if the transaction successfully commits.

I think the delete on the pop3/imap server should happen in this signal.

If things go wrong you import the message twice. That's better than message loss.

@ad-m
Copy link
Collaborator

ad-m commented Sep 5, 2016

@ad-m
Copy link
Collaborator

ad-m commented Sep 5, 2016

Pull requests are welcome to provide callback from ``Mailbox.get_new_mail` to transports about successful mail save.

@guettli
Copy link
Author

guettli commented Sep 21, 2016

I won't use django-mailbox in the next weeks. I won't provide a pull request. Good bye.

@ad-m ad-m closed this as completed Oct 19, 2016
@ad-m ad-m reopened this Oct 19, 2016
@ad-m ad-m added the bug label Oct 19, 2016
@coddingtonbear coddingtonbear changed the title Can mail loss happen like this? Transaction rollbacks can cause mail loss Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants