From ee24c8f7c6f661ce2a27c9343228c3d1d3a50337 Mon Sep 17 00:00:00 2001 From: BenHession Date: Thu, 26 Oct 2023 16:42:25 +0100 Subject: [PATCH 1/5] Add extra error handling to JmsListenerErrorHandler.java --- .../pss/translator/amqp/JmsListenerErrorHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java index 507bd1426..5d26e3415 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java @@ -19,11 +19,17 @@ public class JmsListenerErrorHandler implements ErrorHandler { ); @Override - public void handleError(Throwable t) { + public void handleError(Throwable t) { + + LOGGER.warn("Handling JMS message error due to [{}] with message [{}]", t.getClass(), t.getMessage()); + t.printStackTrace(); Throwable cause = t.getCause(); - Class classOfCause = cause.getClass(); + if (cause == null) { + return; + } + Class classOfCause = cause.getClass(); LOGGER.warn("Caught Error cause of type: [{}], with message: [{}]", classOfCause.toString(), cause.getMessage()); if (RETRYABLE_EXCEPTION_MESSAGES.containsKey(classOfCause)) { From df92245748bafb3ca0e0f943fd3b40eb8d720634 Mon Sep 17 00:00:00 2001 From: BenHession Date: Thu, 26 Oct 2023 16:43:54 +0100 Subject: [PATCH 2/5] Remove unused sql logging --- .../config/DbConnectorConfiguration.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/db-connector/src/main/java/uk/nhs/adaptors/connector/config/DbConnectorConfiguration.java b/db-connector/src/main/java/uk/nhs/adaptors/connector/config/DbConnectorConfiguration.java index c1ad358a5..5f4ca77a7 100644 --- a/db-connector/src/main/java/uk/nhs/adaptors/connector/config/DbConnectorConfiguration.java +++ b/db-connector/src/main/java/uk/nhs/adaptors/connector/config/DbConnectorConfiguration.java @@ -1,16 +1,12 @@ package uk.nhs.adaptors.connector.config; -import java.time.temporal.ChronoUnit; import java.util.List; import javax.sql.DataSource; -import lombok.extern.slf4j.Slf4j; import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.mapper.RowMapper; import org.jdbi.v3.core.spi.JdbiPlugin; -import org.jdbi.v3.core.statement.SqlLogger; -import org.jdbi.v3.core.statement.StatementContext; import org.jdbi.v3.postgres.PostgresPlugin; import org.jdbi.v3.sqlobject.SqlObjectPlugin; import org.springframework.boot.autoconfigure.domain.EntityScan; @@ -19,12 +15,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; +import lombok.extern.slf4j.Slf4j; import uk.nhs.adaptors.connector.dao.ImmunizationSnomedCTDao; import uk.nhs.adaptors.connector.dao.MessagePersistDurationDao; import uk.nhs.adaptors.connector.dao.MigrationStatusLogDao; +import uk.nhs.adaptors.connector.dao.PatientAttachmentLogDao; import uk.nhs.adaptors.connector.dao.PatientMigrationRequestDao; import uk.nhs.adaptors.connector.dao.SnomedCTDao; -import uk.nhs.adaptors.connector.dao.PatientAttachmentLogDao; @Slf4j @Configuration @@ -37,15 +34,6 @@ public Jdbi jdbi(DataSource ds, List jdbiPlugins, List> TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds); Jdbi jdbi = Jdbi.create(proxy); - SqlLogger sqlLogger = new SqlLogger() { - @Override - public void logAfterExecution(StatementContext context) { - LOGGER.debug("sql {}, parameters {}, timeTaken {} ms", context.getRenderedSql(), - context.getBinding().toString(), context.getElapsedTime(ChronoUnit.MILLIS)); - } - }; - jdbi.setSqlLogger(sqlLogger); - jdbiPlugins.forEach(jdbi::installPlugin); rowMappers.forEach(jdbi::registerRowMapper); return jdbi; From e98901205a385d6af19636f49b3983ae99521564 Mon Sep 17 00:00:00 2001 From: BenHession Date: Thu, 26 Oct 2023 17:46:08 +0100 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad33d952c..4d79c09ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +* add additional error handling for unexpected exceptions +* modify SQL statements to guard against out of memory errors + ## [0.15] - 2023-10-24 * Fixed issue with some `ObservationStatement` coded as blood pressure readings not being output into Bundle. From d3a09c8e4b6520a791143760de5c8ab4ad6a6501 Mon Sep 17 00:00:00 2001 From: BenHession Date: Fri, 27 Oct 2023 13:59:07 +0100 Subject: [PATCH 4/5] Add comments to JMS error handler. --- .../pss/translator/amqp/JmsListenerErrorHandler.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java index 5d26e3415..ea4dce9c1 100644 --- a/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java +++ b/gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/amqp/JmsListenerErrorHandler.java @@ -18,8 +18,13 @@ public class JmsListenerErrorHandler implements ErrorHandler { WebClientRequestException.class, "Unable to connect to MHS" ); + /** + * Increment the delivery count for all exceptions, except for RETRYABLE_EXCEPTION_MESSAGES which are retried indefinitely. + * See AbstractMessageListenerContainer + * for documentation. + */ @Override - public void handleError(Throwable t) { + public void handleError(Throwable t) { LOGGER.warn("Handling JMS message error due to [{}] with message [{}]", t.getClass(), t.getMessage()); t.printStackTrace(); @@ -32,6 +37,8 @@ public void handleError(Throwable t) { Class classOfCause = cause.getClass(); LOGGER.warn("Caught Error cause of type: [{}], with message: [{}]", classOfCause.toString(), cause.getMessage()); + // Rety these specific exceptions continuously until they stop happening. + // These retries will happen until the associated transfer times out. if (RETRYABLE_EXCEPTION_MESSAGES.containsKey(classOfCause)) { throw new RuntimeException(RETRYABLE_EXCEPTION_MESSAGES.get(classOfCause)); } From 1626c9f61dbb948a81c891b9c35888050f669613 Mon Sep 17 00:00:00 2001 From: BenHession Date: Fri, 27 Oct 2023 13:59:22 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d79c09ec..8338fa82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] -* add additional error handling for unexpected exceptions -* modify SQL statements to guard against out of memory errors +### Fixed + +* Add additional error handling for exceptions raised when processing PSS queue, and MHS queue messages. +* Fix bug in some SQL statement which caused excessively large amounts of data to be returned, sometimes resulting in a PostgresSQL Out of Memory error. ## [0.15] - 2023-10-24