From 4717bf82f7c4108b2b14da7ea79e9de436445cf8 Mon Sep 17 00:00:00 2001 From: games647 Date: Wed, 12 Apr 2023 09:16:17 +0200 Subject: [PATCH] Acquire save lock before getting a SQL connection --- .../fastlogin/core/storage/SQLStorage.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java index dff841bf..bb941f10 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java @@ -143,11 +143,9 @@ public abstract class SQLStorage implements AuthStorage { @Override public void save(StoredProfile playerProfile) { - try (Connection con = dataSource.getConnection()) { - String uuid = playerProfile.getOptId().map(UUIDAdapter::toMojangId).orElse(null); - - playerProfile.getSaveLock().lock(); - try { + String uuid = playerProfile.getOptId().map(UUIDAdapter::toMojangId).orElse(null); + synchronized (playerProfile) { + try (Connection con = dataSource.getConnection()) { if (playerProfile.isSaved()) { try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) { saveStmt.setString(1, uuid); @@ -174,11 +172,9 @@ public abstract class SQLStorage implements AuthStorage { } } } - } finally { - playerProfile.getSaveLock().unlock(); + } catch (SQLException ex) { + core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex); } - } catch (SQLException ex) { - core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex); } }