title: Intermittent "Communications link failure"
body: <p>Not a duplicate, none of the proposed fixes solve my problem.</p>
  
  <p>Adding requested information to reopen issue:</p>
  
  <p>OS: Amazon Linux AMI release 2018.03</p>
  
  <p>Java: 1.8 - more specifically on production it is OpenJDK build 1.8.0_201-b09</p>
  
  <p>Spring Boot: 2.1.2.RELEASE</p>
  
  <p>Database: AWS RDS MariaDB version 5.7.16</p>
  
  <p>Here is the link to a gist containing the MySQL error log:
  <a href="https://gist.github.com/urielb/6675ec2a80f5fbca630e52ca0b9d2b2a" rel="nofollow noreferrer">https://gist.github.com/urielb/6675ec2a80f5fbca630e52ca0b9d2b2a</a></p>
  
  <p>In the MySQL logs the only thing that appeared a lot before the crashing part I gisted above is this:</p>
  
  <pre><code>2019-07-11T19:26:18.888986Z 791 [Note] Aborted connection 791 to db: 'database' user: 'user' host: 'IP_ADDRESS' (Got an error reading communication packets)
  </code></pre>
  
  <p>But other than that, I couldn't find anything on the server logs.</p>
  
  <p><strong>END OF EDIT #2</strong></p>
  
  <p>This one has me scratching my head over the last couple days.</p>
  
  <p>We have a Java Spring Boot application with access to a MySQL database.</p>
  
  <p>We have an action that should save some data on the server, and some times it works fine, but other times it fails, but I still haven't been able to find a pattern on why it happens. Only happens in production.</p>
  
  <p>There is no user input other then clicking a button, but when we try to get a connection to the database to perform the desired operations, the connection simple isn't made.</p>
  
  <pre><code>public static Connection getConnection()
  {
      try
      {
          Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
          Connection conn = DriverManager.getConnection(Conf.getDatabaseConnectionString(), Conf.getDatabaseConnectionUser(), Conf.getDatabaseConnectionPassword());
          return conn;
      } catch (SQLException e)
      {
          logger.error("Failed to establish a connection to the database (SQLException): " + e.getMessage());
          return null;
      }
      ...
  }
  </code></pre>
  
  <p>The connection string the same as below, except for pointing to the production server.</p>
  
  <pre><code>jdbc:mysql://localhost:3306/database?useSSL=false&amp;allowPublicKeyRetrieval=false
  </code></pre>
  
  <p>That's basically the function except that there are more catches that check if it wasn't possible to make a connection, why was that, and returns a null.</p>
  
  <p>So, the problem is, this method is often returning null. At first I thought it could be a 'TOO MANY ConnectionS' issue, but upon further inspection I realized that was not the case. Apparently it fails with a</p>
  
  <pre><code>...CJCommunicationsException: Communications link failure. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  </code></pre>
  
  <p>But I really have no idea what may be causing this, why is this issue intermittent? I have no clue on where to begin to solve this problem. I've implemented a Hikari connection pool in hope it was only a case of too many connections.</p>
  
  <p>I've read some articles suggesting some configurations on the MySQL server, specially regarding the listing address and ports, but using AWS RDS all we have to do is configure the security groups, also that wouldn't address the intermittency of the problem...</p>
  
  <p>Anyone has ever experienced something similar? I am open to any ideas or suggestions at the moment.</p>