fix: Prevent possible infinite loop with invalid smtp row#7746
Conversation
link2xt
left a comment
There was a problem hiding this comment.
Can we just move the DELETE FROM smtp above?
|
We can, but why? It seems weird to abort sending messages, early-return from Or do you mean, in addition to what I already did in the PR here? |
If we fail to mark the message as failed there is something really wrong with the database or the filesystem or hardware. Ignoring errors everywhere just adds more untested codepaths. We also just got another one case in another PR, also making more codepaths: |
I agree that in this particular function it's better to move EDIT: And |
Make sure that the row is deleted from SMTP even if we didn't manage to mark the message as failed
50481bf to
aa6b8e9
Compare
|
Early-returning with |
|
I think that the real problem isn't "new code paths", but rather a state when a message remains in |
If you have a code that looks like this: then you have 4 possible paths: foo fails, bar fails, baz fails or everything succeeds. If you ignore errors like this, you get 8 possible code paths: |
|
If the "failed" branches are independent from each other (there's no correlation probabilistically), it's enough to have 4 tests -- everything succeeds, |
If
Message::load_from_db_optional()orset_msg_failed()fails, we shouldn't early-return. Because it's important that the lineexecute("DELETE FROM smtp WHERE id=?", (rowid,))is executed in order to prevent an infinite loop, if one of these functions fails.