spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.82k stars 40.6k forks source link

Add default timeout when smtp client enters infinite reconnect state #42152

Closed Miguel-99 closed 1 month ago

Miguel-99 commented 1 month ago

Description

i encountered an issue when using spring-boot-starter-mail dependency. When the smtp client fails to connect to the configured host and port, it enters an infinite reconnection state impacting on MailHealthIndicator becoming stuck attempting to resolve the connection. This causes the /actuator/health endpoint to hang and never return a response

if monitoring tools or services are evaluationg /actuator/health endpoint, they may not indicate an HTTP status error but instead report a timeout. This makes it difficult to identify the real cause of failure

Steps to reproduce:

  1. configure mail properties with smpt settings that points to an unreachable host
  2. attempt to send an email using JavaMailSender

Expected behaviour:

Fail after a certain default time with an error message

Actual behaviour:

Suggestion:

provide a default timeout configuration that prevents the app from getting stuck in an infinite reconnection state

Environment:

Hi, this is my first issue, hope its well structured.

wilkinsona commented 1 month ago

We generally try to align our defaults with those of the underlying technology. In this case, that means an infinite timeout. We have documented a recommendation to configure custom timeouts:

In particular, certain default timeout values are infinite, and you may want to change that to avoid having a thread blocked by an unresponsive mail server