nithril / smtp-connection-pool

SMTP Connection Pool
Apache License 2.0
47 stars 19 forks source link

Exception while borrowObject() #23

Closed santushet closed 4 years ago

santushet commented 4 years ago

Trying to get the connection from pool using method smtpConnectionPool.borrowObject(),but getting exception when the load on the server is high. I am running with threadpool of size 40 for processing emails of approx 2000 per second on aws t2.medium instance size. Could you please advice how to troubleshoot this issue. This is the code and it is going to last catch statement.

  private void sendPooled(MimeMessage message) throws Exception {
    logger.debug("Sending MimeMessage using pooled connection; see config " + CONFIG_SMTPCONNECTIONPOOLING_PREFIX + ".* for parameters");
    // borrow an object in a try-with-resource statement or call "close" by yourself
    try (ClosableSmtpConnection transport = smtpConnectionPool.borrowObject()) {
      transport.sendMessage(message);
      metricsLogger.logMetricCountOne("email.sent.pooled");
    } catch (MessagingException mE) {
      logger.warn("Failed send with message exception", mE);
      throw mE;
    } catch (Exception e) {
      logger.warn("Huh? Exception during borrowObject?", e);
      throw e;
    }
  }
nithril commented 4 years ago

Could you please share the exception?

santushet commented 4 years ago

I am not able to give complete log trace. However, receiving generic error from this block catch (Exception e) { logger.warn("Huh? Exception during borrowObject?", e); throw e; In the SMTP, the maximum number of connections that an SMTP client may make simultaneously is 50. Is it possible that this issue is could be from max limit? Also we have observed only when there are huge emails getting processed.

nithril commented 4 years ago

Might be, it depends on how you have configured the pool (blocking or not)

santushet commented 4 years ago

Yes, it was issue due to insufficient SMTP connections. Closing this ticket.