Skip to content

Commit 838cf34

Browse files
committed
max allowed packet < 16Mb skipping packet correction
1 parent e1b02d0 commit 838cf34

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ install:
2929
connector-test-machine/launch.bat -t "$srv" -v "$v" -d testj
3030
;;
3131
linux)
32-
source connector-test-machine/launch.sh -t "$srv" -v "$v" -d testj -n 0 -l "$local"
32+
source connector-test-machine/launch.sh -t "$srv" -v "$v" -d testj -n 0 -l "$local" -p "$packet"
3333
;;
3434
esac
3535
jobs:
@@ -47,6 +47,7 @@ jobs:
4747
- env: srv=mariadb v=10.3 local=1
4848
- env: srv=mariadb v=10.4 local=1
4949
- env: srv=mariadb v=10.5
50+
- env: srv=mariadb v=10.5 packet=8
5051
- env: srv=mariadb v=10.5 local=1 BENCH=1
5152
- env: srv=maxscale
5253
- env: srv=skysql

src/main/java/org/mariadb/jdbc/client/ClientImpl.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.mariadb.jdbc.util.constants.HaMode;
5858
import org.mariadb.jdbc.util.constants.ServerStatus;
5959
import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
60+
import org.mariadb.jdbc.util.exceptions.MaxAllowedPacketException;
6061
import org.mariadb.jdbc.util.log.Logger;
6162
import org.mariadb.jdbc.util.log.Loggers;
6263

@@ -427,6 +428,11 @@ public int sendQuery(ClientMessage message) throws SQLException {
427428
try {
428429
return message.encode(writer, context);
429430
} catch (IOException ioException) {
431+
if (ioException instanceof MaxAllowedPacketException) {
432+
throw exceptionFactory
433+
.withSql(message.description())
434+
.create("Packet too big for current server max_allowed_packet value", "HZ000", ioException);
435+
}
430436
destroySocket();
431437
throw exceptionFactory
432438
.withSql(message.description())
@@ -462,12 +468,13 @@ public List<Completion> executePipeline(
462468
for (int i = 0; i < messages.length; i++) {
463469
responseMsg[i] = sendQuery(messages[i]);
464470
}
465-
for (; readCounter < messages.length; readCounter++) {
466-
for (int j = 0; j < responseMsg[readCounter]; j++) {
471+
for (; readCounter < messages.length; ) {
472+
readCounter++;
473+
for (int j = 0; j < responseMsg[readCounter - 1]; j++) {
467474
results.addAll(
468475
readResponse(
469476
stmt,
470-
messages[readCounter],
477+
messages[readCounter - 1],
471478
fetchSize,
472479
maxRows,
473480
resultSetConcurrency,
@@ -479,13 +486,13 @@ public List<Completion> executePipeline(
479486
} catch (SQLException sqlException) {
480487

481488
// read remaining results
482-
for (int i = ++readCounter; i < messages.length; i++) {
483-
for (int j = 0; j < responseMsg[readCounter]; j++) {
489+
for (int i = readCounter; i < messages.length; i++) {
490+
for (int j = 0; j < responseMsg[i]; j++) {
484491
try {
485492
results.addAll(
486493
readResponse(
487494
stmt,
488-
messages[readCounter],
495+
messages[i],
489496
fetchSize,
490497
maxRows,
491498
resultSetConcurrency,

src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.mariadb.jdbc.MariaDbBlob;
4141
import org.mariadb.jdbc.MariaDbClob;
4242
import org.mariadb.jdbc.Statement;
43+
import org.mariadb.jdbc.util.exceptions.MaxAllowedPacketException;
4344

4445
public class PreparedStatementParametersTest extends Common {
4546

@@ -450,7 +451,33 @@ public void bigSend(Connection con, String st) throws SQLException {
450451
ResultSet rs = stmt.executeQuery("SELECT t2 from bigTest WHERE t1 = 1");
451452
assertTrue(rs.next());
452453
assertEquals(st, rs.getString(1));
453-
stmt.execute("COMMIT");
454+
con.commit();
455+
}
456+
457+
@Test
458+
public void bigSendError() throws SQLException {
459+
int maxAllowedPacket = getMaxAllowedPacket();
460+
Assumptions.assumeTrue(maxAllowedPacket < 10 * 1024 * 1024);
461+
char[] arr = new char[10 * 1024 * 1024];
462+
for (int pos = 0; pos < arr.length; pos++) {
463+
arr[pos] = (char) ('A' + (pos % 60));
464+
}
465+
String st = new String(arr);
466+
bigSendError(sharedConn, st);
467+
bigSendError(sharedConnBinary, st);
468+
}
469+
470+
471+
public void bigSendError(Connection con, String st) throws SQLException {
472+
Statement stmt = con.createStatement();
473+
stmt.execute("TRUNCATE bigTest");
474+
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
475+
try (PreparedStatement prep = con.prepareStatement("INSERT INTO bigTest VALUES (?, ?)")) {
476+
prep.setInt(1, 1);
477+
prep.setString(2, st);
478+
assertThrowsContains(SQLException.class, () -> prep.execute(), "Packet too big for current server max_allowed_packet value");
479+
}
480+
con.commit();
454481
}
455482

456483
@FunctionalInterface

0 commit comments

Comments
 (0)