Uploaded image for project: 'Commons Email'
  1. Commons Email
  2. EMAIL-100

The default connection timeout should be set to a reasonable default value

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.3
    • 1.3
    • None

    Description

      Commons email is a simplifying wrapper around another API. It is also expected to be used in server environments.

      By default there are no connection timeouts set, this can (and does) cause threads to hang indefinitely. Since the goal of commons email is to simplify configuration, there should be a reasonable default value set. The default config should not risk a hanging a server.

      This situation was easily produced using the gmail SMTP gateway. When > ~10 open connections exists the SMTP server starts resetting connections. Once in a while this will cause a thread to hang in IO wait indefinitely. The solution was to set the timeouts, but it is very easy to overlook the need to set this timeout, and natural to expect the wrapper class to handle such details.

      The snippets of code below belong in 1.3 Snapshot [as of 8/21/2010] org.apache.commons.mail.Email, they set a default of 1 minute timeout for connection and IO and update the javadocs.

      Line 109:
      ====================================================================
      /**

      • Socket connection timeout value in milliseconds. Default is 1 minute.
      • @since 1.2
        */
        public static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout";

      /**

      • Socket I/O timeout value in milliseconds. Default is 1 minute.
      • @since 1.2
        */
        public static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";

      Line 240:
      ====================================================================
      /** socket I/O timeout value in milliseconds */
      protected int socketTimeout = 60000;
      /** socket connection timeout value in milliseconds */
      protected int socketConnectionTimeout = 60000;

      Line 1504:
      ====================================================================

      /**

      • Get the socket connection timeout value in milliseconds.
      • Default is 1 minute.
        *
      • @return the timeout in milliseconds.
      • @since 1.2
        */
        public int getSocketConnectionTimeout() { return this.socketConnectionTimeout; }

      /**

      • Set the socket connection timeout value in milliseconds.
      • Default is 1 minute.
        *
      • @param socketConnectionTimeout the connection timeout
      • @since 1.2
        */
        public void setSocketConnectionTimeout(int socketConnectionTimeout) { this.socketConnectionTimeout = socketConnectionTimeout; }

      /**

      • Get the socket I/O timeout value in milliseconds.
      • Default is 1 minute.
        *
      • @return the socket I/O timeout
      • @since 1.2
        */
        public int getSocketTimeout() { return this.socketTimeout; }

      /**

      • Set the socket I/O timeout value in milliseconds.
      • Default is 1 minute.
        *
      • @param socketTimeout the socket I/O timeout
      • @since 1.2
        */
        public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; }

      Attachments

        Activity

          People

            sgoeschl Siegfried Goeschl
            davidparks21 David Parks
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified