Skip to content

Commit

Permalink
Merge pull request #97 from Team-Umbba/fix/#95-notification_server_error
Browse files Browse the repository at this point in the history
[FIX] 커넥션 누수를 해결하기 위해 em.close() 코드 추가
  • Loading branch information
ddongseop authored Aug 14, 2023
2 parents 94a3e38 + c0a3aeb commit 9fbc22b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sopt.org.umbba.common.sqs.dto.MessageDto;

import java.util.Map;
import java.util.Objects;
import java.util.UUID;

/**
Expand Down Expand Up @@ -51,7 +52,12 @@ public void produce(MessageDto message) {
.withMessageAttributes(createMessageAttributes(message.getType()));

amazonSqs.sendMessage(request);
log.info(MessageUtils.generate(SQS_QUEUE_REQUEST_LOG_MESSAGE, request));
if (Objects.equals(message.getType(), MessageType.SLACK)) {
log.info(MessageUtils.generate(SQS_QUEUE_REQUEST_LOG_MESSAGE, "Slack 500 Error 내용"));
} else {
log.info(MessageUtils.generate(SQS_QUEUE_REQUEST_LOG_MESSAGE, request));
}


} catch (JsonProcessingException e) {
log.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -32,6 +33,8 @@ public Optional<Parentchild> findByUserId(Long userId) {

} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}

}
Expand All @@ -49,6 +52,8 @@ public Optional<User> findMatchUserByUserId(Long userId) {
return Optional.ofNullable(user);
} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}
}

Expand All @@ -58,9 +63,15 @@ public List<String> findFcmTokensById(Long parentchildId) {
"JOIN Parentchild pc ON pc.id = u.parentChild.id " +
"WHERE pc.id = :id";

return em.createQuery(jpql, String.class)
.setParameter("id", parentchildId)
.getResultList();
try {
return em.createQuery(jpql, String.class)
.setParameter("id", parentchildId)
.getResultList();
} catch (NoResultException e) {
return new ArrayList<>();
} finally {
em.close();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public Optional<List<QnA>> findQnASByUserId(Long userId) {
} catch (NoResultException e) {

return Optional.empty();
} finally {
em.close();
}
}

Expand Down

0 comments on commit 9fbc22b

Please sign in to comment.