Skip to content

Commit

Permalink
Do not throw from cache removal listener
Browse files Browse the repository at this point in the history
Such exceptions are suppressed. Failure to close a connection is a
problem (resource leak), so log such exceptions.
  • Loading branch information
findepi committed Mar 22, 2024
1 parent 4b76d8e commit 072bfe4
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.errorprone.annotations.ThreadSafe;
import com.google.errorprone.annotations.concurrent.GuardedBy;
import com.google.inject.Inject;
import io.airlift.log.Logger;
import io.trino.spi.TrinoException;
import io.trino.spi.connector.ConnectorSession;
import org.gaul.modernizer_maven_annotations.SuppressModernizer;
Expand All @@ -36,6 +37,8 @@
public final class ReusableConnectionFactory
implements ConnectionFactory, JdbcQueryEventListener
{
private static final Logger log = Logger.get(ReusableConnectionFactory.class);

@GuardedBy("this")
private final Cache<String, Connection> connections;
private final ConnectionFactory delegate;
Expand Down Expand Up @@ -75,8 +78,8 @@ private static void onRemoval(RemovalNotification<String, Connection> notificati
requireNonNull(notification.getValue(), "notification.getValue() is null");
notification.getValue().close();
}
catch (SQLException e) {
throw new TrinoException(JDBC_ERROR, e);
catch (SQLException | RuntimeException e) {
log.warn(e, "Failed to close connection %s for %s", notification.getValue(), notification.getKey());
}
}

Expand Down

0 comments on commit 072bfe4

Please sign in to comment.