mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(database): reconnect a custom JDBC data source whose session was lost (#4675)
When a proxy or tunnel dropped an idle custom JDBC connection, every later statement failed and the source still showed Connected: the cached pool was only marked closed when the IDE closed it. After a failed statement the bridge now checks Connection.isValid (new valid op); an invalid or orphaned session closes the pool so the next statement or Connect reconnects. Keep-alive for JDBC uses the same check (and its option shows in the dialog); failures log at info.
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.logging.Logger;
|
||||
public class SelfTest {
|
||||
public static class Fixture implements Driver {
|
||||
private boolean readonly;
|
||||
private boolean dropped;
|
||||
private int changes;
|
||||
private Path started;
|
||||
|
||||
@@ -36,6 +37,8 @@ public class SelfTest {
|
||||
case "getMetaData" -> meta;
|
||||
case "close" -> null;
|
||||
case "createStatement" -> statement();
|
||||
case "isClosed" -> false;
|
||||
case "isValid" -> !dropped;
|
||||
default -> throw new SQLFeatureNotSupportedException();
|
||||
});
|
||||
}
|
||||
@@ -53,6 +56,7 @@ public class SelfTest {
|
||||
throw new SQLException("statement cancelled");
|
||||
}
|
||||
if (sql.equals("write") && readonly) throw new SQLException("read-only");
|
||||
if (sql.equals("drop")) { dropped = true; throw new SQLException("connection reset"); }
|
||||
changes++;
|
||||
yield false;
|
||||
}
|
||||
@@ -122,6 +126,12 @@ public class SelfTest {
|
||||
send(out, 5, "query", "after cancel", "0", "2");
|
||||
var result = reply(in);
|
||||
assert result[0] == 1 && result[result.length - 1] == 2;
|
||||
send(out, 6, "valid");
|
||||
assert new String(reply(in), StandardCharsets.UTF_8).contains("true");
|
||||
send(out, 7, "query", "drop", "0", "2");
|
||||
assert reply(in)[0] == 0;
|
||||
send(out, 8, "valid");
|
||||
assert new String(reply(in), StandardCharsets.UTF_8).contains("false");
|
||||
} finally {
|
||||
child.destroyForcibly().waitFor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user