-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Irregular errors in driver when multiple statements from one connection used concurrently #115
Comments
The same issue here. It looks like driver not longer sync on connection and concurrent calls of any SQL query execution breaks native protocol. |
Thanks for the heads up, I ran this with a driver version before 2.1.0.10 and it fixed my issue. Obviously not ideal but it got me what I needed. |
After some investigation I realized that multithreading was broken exactly in 2.1.0.9, after serverless Redshift support was added. Here is the snippet which reproduces the problem. import com.amazon.redshift.jdbc42.Driver;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class RedshiftTestMT {
public static void main(String[] args) throws Exception {
System.out.println("Test MT");
Driver rdrv = new Driver();
Properties props = new Properties();
props.put("AccessKeyID", "<access-key>");
props.put("SecretAccessKey", "<secret-key>");
props.put("DbUser", "awsuser");
try (Connection connection = rdrv.connect("jdbc:redshift:iam://<server-addr>:5439/dev", props);) {
System.out.println("Run tests");
List<Thread> startedThreads = new ArrayList<>();
for (int i = 0; i < 20; i++) {
int finalI = i;
Thread thread = new Thread("Thread " + finalI) {
@Override
public void run() {
try {
runSimpleQuery(connection, finalI);
} catch (SQLException e) {
e.printStackTrace();
}
}
};
startedThreads.add(thread);
thread.start();
}
for (Thread thread : startedThreads) {
thread.join();
}
}
System.out.println("Finished");
}
private static void runSimpleQuery(Connection connection, int index) throws SQLException {
System.out.println("Run for thread " + index);
try (PreparedStatement stat = connection.prepareStatement("SELECT 'hello world!'")) {
try (ResultSet results = stat.executeQuery()) {
while (results.next()) {
System.out.println(results.getString(1));
}
}
}
System.out.println("\tFinished for thread " + index);
}
} Probably it is somehow related to serverless Redshift support.. |
Driver version
2.1.0.26
Redshift version
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.63269
Client Operating System
macOS Version 14.3.1
JAVA/JVM version
17.0.3
Problem description
Expected: no errors
Actual: one of the statements fails due to
Unexpected packet type
errorJDBC trace logs
Reproduction code
This code demonstrates the problem, but it may not always occur due to timing variations.
The text was updated successfully, but these errors were encountered: