Improve SMTP error handling #994
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replaces
try_smtp!with a more resilient way of handling network errors and correctly shutting down the connection afterwards.I'm not too happy about how it turned out, so I'm opening as draft. We are not sending QUIT anymore when encountering certain kinds of errors, plus other unclean things in the implementation. Having to send QUIT like we did before also feels expensive in the sync implementation, as we're potentially taking precious time from the thread to slowly close the connection 🤔.
It should fix/improve the situtation reported in https://matrix.to/#/!jZPOAKPWNeZkNemCEi:gitter.im/$hTxrNpVLYWtAM9a2OciwiGDDGDY3LlZKdnA50cHzc8A?via=gitter.im&via=matrix.org&via=0x.badd.cafe / dani-garcia/vaultwarden#4996 (comment).
The modifications on the async transport also make the implementation cancel safe (in a very conservative way), which may help when connection pooling is enabled and used (Vaultwarden does not use connection pooling as of now).