-
-
Notifications
You must be signed in to change notification settings - Fork 274
Test SMTP connection when claiming from pool #250
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
Comments
Interesting addition, but I'm not sure the code would work there since Simple Java Mail marks a claimed Transport resource as faulty in case of any exception and so it would never allocate for reuse. Unless that mechanism is broken... |
In my testing after it’s claimed and an exception is encountered during use, the resource isn’t used again. So that’s working fine. The test I’m proposing is after claim and before usage
Hopefully that makes sense. Really appreciated your quick reply!!
|
Hmm, makes sense. I'd need to look into the performance overhead first though of a connection test. If it is negligent, then no worries. Otherwise I'd like to introduce a cool down property so that it only rechecks the connection after a user defined threshold (so during bursts of emails it won't check the connection each reuse). |
The performance hit can be low when the NOOP command is used: it is just one extra command added to all the other commands required to send an email.
If you know the email server will respond properly to a NOOP command, a method like the one below can be used to validate a connection before "checkout of the pool":
|
It's a little confusing. Three things: 1.
So this should not be possible. A transport that broke down would be marked faulty when returning to the pool, so it will be destroyed. If I initially understood you correctly, your use case is about connections that were returned just fine (or simply kept warm but never used before) and the connection breaks down while idle in the connection pool. Then when claiming (allocating), the connection should be checked just to be sure. 2.
I find this a little difficult to unify into a single simple api. I would like to solve this for my users on higher an abstraction level, but the whole 'if the server supports it' makes it confusing. I would like to offer my users something like this: mailerBuilder
.withConnectionPoolDefensiveClaimingEnabled() // with mail.smtp.noop.strict
.withConnectionPoolDefensiveClaimingLegacyMode() // turn off mail.smtp.noop.strict Or something like that. 3.Regarding |
Sorry for the confusion, I'll try to clarify. |
It's been a while! Recently, in January, I've released a version that, when being reclaimed, reconnects if the connection was lost in the mean time. Would that solve this problem? |
Closing due to lack of response. Assuming the change covers the use case reported here. |
I'm using simple-java-mail 6.0.3 and wondering if there is a way to configure the mailer to check connectivity when claiming. I've found it's possible that broken connections in the pool are re-used when setting
MailerGenericBuilder.withConnectionPoolExpireAfterMillis
to a longer expiration timeLooking at the implementation I found that
Allocator.allocateForReuse
seems to be the appropriate place for this check. However the concreteTransportAllocator
doesn't override this method -- would something like the following be reasonable?See https://github.com/eclipse-ee4j/mail/blob/1.6.3/mail/src/main/java/com/sun/mail/smtp/SMTPTransport.java#L1419 for
SMTPTransport.isConnected
The text was updated successfully, but these errors were encountered: