I think I have all my calls for new connections in try/with blocks, but
things went bump in the night at AWS/RDS yesterday and I'm wondering if
I missed one or if the try/with isn't as safe as I thought.
00:10:12.201 [https-jsse-nio-10.0.2.28-15002-exec-11] INFO
edu.utah.camplab.jx.PayloadFromMux -
bulk."rjs_GEV15_20_074d449b_c3ba_499f_83e3_f48427fe0156": Begin
transfer from bulk to segment
26-May-2021 00:10:55.092 WARNING [Tomcat JDBC Pool
Cleaner[1731185718:1621976215058]]
org.apache.tomcat.jdbc.pool.ConnectionPool.abandon Connection has
been abandoned PooledConnection[org.postgresql.jdbc.PgConnection@2e\
cd1168]:java.lang.Exception
at
org.apache.tomcat.jdbc.pool.ConnectionPool.getThreadDump(ConnectionPool.java:1163)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:816)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:660)
at
org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:198)
at
org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:132)
at
org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:90)
at
edu.utah.camplab.servlet.AbstractSGSServlet.getDbConn(AbstractSGSServlet.java:123)
at
edu.utah.camplab.servlet.AbstractSGSServlet.getDbConn(AbstractSGSServlet.java:105)
at
edu.utah.camplab.servlet.PayloadSaveServlet.doPost(PayloadSaveServlet.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
in my tomcat log. I see *nothing* that matches this in the AWS/RDS log
views.
And here's the getDbConn call in the doPost method (though I see it has
a superfluous close() call):
protected void doPost(HttpServletRequest req, HttpServletResponse
resp) {
//HashMap<String, ArrayList<String>> pmap = getParameterMap(req);
logger.error("payload save called");
try (Connection copyConn = getDbConn(req, resp)) {
ObjectMapper jsonMapper = JsonMapper.builder().addModule(new
JavaTimeModule()).build();
jsonMapper.setSerializationInclusion(Include.NON_NULL);
AbstractPayload payload =
jsonMapper.readValue(req.getInputStream(), AbstractPayload.class);
logger.error("received payload");
String redoUrl =
String.format("jdbc:postgresql://%s:%d/%s", getDbHost(),
getDbPort(), getDbName(req));
payload.setConnection(copyConn);
payload.setDbUrl(redoUrl);
payload.write();
logger.error("finished db write");
resp.setContentType("plain/text");
resp.setStatus(200);
resp.getOutputStream().write("SGS_OK".getBytes());
resp.getOutputStream().flush();
resp.getOutputStream().close();
copyConn.close();
}
catch
(com.fasterxml.jackson.databind.exc.MismatchedInputException mie) {
logger.error("transform failed: " + mie.getMessage());
resp.setContentType("plain/text");
resp.setStatus(461);
sendBadNews(resp, mie, "json formatting issue, perhaps");
}
catch (IOException | SQLException ioe) {
resp.setStatus(460);
sendBadNews(resp, ioe, "database trouble, likely");
}
}