mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 19:24:47 +02:00
Acquire save lock before getting a SQL connection
This commit is contained in:
@@ -143,11 +143,9 @@ public abstract class SQLStorage implements AuthStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(StoredProfile playerProfile) {
|
public void save(StoredProfile playerProfile) {
|
||||||
try (Connection con = dataSource.getConnection()) {
|
|
||||||
String uuid = playerProfile.getOptId().map(UUIDAdapter::toMojangId).orElse(null);
|
String uuid = playerProfile.getOptId().map(UUIDAdapter::toMojangId).orElse(null);
|
||||||
|
synchronized (playerProfile) {
|
||||||
playerProfile.getSaveLock().lock();
|
try (Connection con = dataSource.getConnection()) {
|
||||||
try {
|
|
||||||
if (playerProfile.isSaved()) {
|
if (playerProfile.isSaved()) {
|
||||||
try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) {
|
try (PreparedStatement saveStmt = con.prepareStatement(UPDATE_PROFILE)) {
|
||||||
saveStmt.setString(1, uuid);
|
saveStmt.setString(1, uuid);
|
||||||
@@ -174,13 +172,11 @@ public abstract class SQLStorage implements AuthStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
playerProfile.getSaveLock().unlock();
|
|
||||||
}
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex);
|
core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
Reference in New Issue
Block a user