Skip to content

Commit 70f65ef

Browse files
authored
add failing test case for #223 (#226)
ignore packets after aborted query
1 parent ac94ebc commit 70f65ef

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Sources/MySQL/Connection/MySQLConnectionHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ final class MySQLConnectionHandler: ChannelInboundHandler {
103103
case .waiting:
104104
switch packet {
105105
case .ok: break
106-
default: fatalError("Unexpected packet: \(packet)")
106+
default: break // ignore packets here, they may be left overs from an aborted query
107107
}
108108
case .callback(let promise, let callback):
109109
do {

Sources/MySQL/Pipeline/MySQLPacketDecoder.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class MySQLPacketDecoder: ByteToMessageDecoder {
3939
switch session.eofState {
4040
case .waiting:
4141
if !capabilities.contains(.CLIENT_DEPRECATE_EOF) {
42-
print("decode deprecated EOF")
4342
return try decodeBasicPacket(ctx: ctx, buffer: &buffer, capabilities: capabilities, forwarding: false)
4443
}
4544
default: break

Tests/MySQLTests/MySQLTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,24 @@ class MySQLTests: XCTestCase {
344344
XCTAssertEqual("\(time)", "2010-12-16 2:27:49.0")
345345
}
346346

347+
// https://github.com/vapor/mysql/issues/223
348+
func testGH223() throws {
349+
let conn = try MySQLConnection.makeTest()
350+
_ = try conn.simpleQuery("DROP TABLE IF EXISTS `Todo`").wait()
351+
_ = try conn.simpleQuery("CREATE TABLE `Todo` (id int, name text)").wait()
352+
_ = try conn.simpleQuery("INSERT INTO `Todo` VALUES (1, 'a')").wait()
353+
_ = try conn.simpleQuery("INSERT INTO `Todo` VALUES (2, 'b')").wait()
354+
do {
355+
try conn.query("SELECT * FROM `Todo`") { row in
356+
print(row)
357+
throw MySQLError(identifier: "asdf", reason: "foo")
358+
}.wait()
359+
XCTFail("should have thrown")
360+
} catch {
361+
// pass
362+
}
363+
}
364+
347365
static let allTests = [
348366
("testBenchmark", testBenchmark),
349367
("testSimpleQuery", testSimpleQuery),
@@ -364,6 +382,7 @@ class MySQLTests: XCTestCase {
364382
("testZeroRowSelect", testZeroRowSelect),
365383
("testZeroLengthArray", testZeroLengthArray),
366384
("testMySQLTimeDescription", testMySQLTimeDescription),
385+
("testGH223", testGH223),
367386
]
368387
}
369388

0 commit comments

Comments
 (0)