vapor / mysql-nio

🐬 Non-blocking, event-driven Swift client for MySQL.
MIT License
91 stars 26 forks source link

MySQLConnectionHandler.swift Fatal error: unhandled packet: ByteBuffer #92

Closed yong-ya closed 1 year ago

yong-ya commented 1 year ago

Describe the bug

Server periodically crashes with the following output:

MySQLNIO/MySQLConnectionHandler.swift:89: Fatal error: unhandled packet: ByteBuffer { readerIndex: 0, writerIndex: 145, readableBytes: 145, capacity: 145, storageCapacity: 32768, slice: _ ByteBufferSlice { 4..<149 }, storage: 0x00007f78d8037030 (32768 bytes) }

ByteBufferSlice { 4..<149 }, storage: 0x00007f78d8037030 (32768 bytes) } readable bytes (max 1k): [ ff bf 0f 23 48 59 30 30 30 54 68 65 20 63 6c 69 65 6e 74 20 77 61 73 20 64 69 73 63 6f 6e 6e 65 63 74 65 64 20 62 79 20 74 68 65 20 73 65 72 76 65 72 20 62 65 6 3 61 75 73 65 20 6f 66 20 69 6e 61 63 74 69 76 69 74 79 2e 20 53 65 65 20 77 61 69 74 5f 74 69 6d 65 6f 75 74 20 61 6e 64 20 69 6e 74 65 72 61 63 74 69 76 65 5f 74 69 6d 65 6f 75 74 20 66 6f 72 20 63 6f 6e 66 69 67 75 72 69 6e 67 20 74 68 69 73 20 62 65 68 61 76 69 6f 72 2e ]

Received signal 4. Backtrace: 0x560ba09f1eaf, Backtrace.(printBacktrace in _B82A8C0ED7C904841114FDF244F9E58E)(signal: Swift.Int32) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift- backtrace/Sources/Backtrace/Backtrace.swift:66 0x560ba09f21d9, closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.bui ld/checkouts/swift-backtrace/Sources/Backtrace/Backtrace.swift:80 0x560ba09f21f8, @objc closure #1 (Swift.Int32) -> () in static Backtrace.Backtrace.install(signals: Swift.Array) -> () at /home/yong-yan/projects/MerlinDaemonAPIServe r/:0 0x7f78fb67851f 0x7f78fbc663cf 0x7f78fbc666b0 0x7f78fbf0f3e5 0x560ba0fc0abc, MySQLNIO.MySQLConnectionHandler.channelRead(context: NIOCore.ChannelHandlerContext, data: NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.b uild/checkouts/mysql-nio/Sources/MySQLNIO/MySQLConnectionHandler.swift:89 0x560ba0fce438, protocol witness for NIOCore._ChannelInboundHandler.channelRead(context: NIOCore.ChannelHandlerContext, data: NIOCore.NIOAny) -> () in conformance MySQLNIO.MySQLConnection Handler : NIOCore._ChannelInboundHandler in MySQLNIO at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba1128e38, NIOCore.ChannelHandlerContext.(invokeChannelRead in _F5AC316541457BD146E3694279514AA3)(NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.buil d/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1702 0x560ba1128ea6, NIOCore.ChannelHandlerContext.(invokeChannelRead in _F5AC316541457BD146E3694279514AA3)(NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.buil d/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1704 0x560ba112d82b, NIOCore.ChannelHandlerContext.fireChannelRead(NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/Cha nnelPipeline.swift:1515 0x560ba0ffc927, MySQLNIO.MySQLPacketDecoder.decode(context: NIOCore.ChannelHandlerContext, buffer: inout NIOCore.ByteBuffer) throws -> NIOCore.DecodingState at /home/yong-yan/proj ects/MerlinDaemonAPIServer/.build/checkouts/mysql-nio/Sources/MySQLNIO/Packet/MySQLPacketDecoder.swift:32 0x560ba0ffcf4c, protocol witness for NIOCore.ByteToMessageDecoder.decode(context: NIOCore.ChannelHandlerContext, buffer: inout NIOCore.ByteBuffer) throws -> NIOCore.DecodingState in confo rmance MySQLNIO.MySQLPacketDecoder : NIOCore.ByteToMessageDecoder in MySQLNIO at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba114833c, closure #1 (inout A, inout NIOCore.ByteBuffer) throws -> NIOCore.DecodingState in NIOCore.ByteToMessageHandler.(decodeLoop in _3B15959193A57E0C1E789632BC533F5E)(context: N IOCore.ChannelHandlerContext, decodeMode: NIOCore.ByteToMessageHandler.(DecodeMode in _3B15959193A57E0C1E789632BC533F5E)) throws -> NIOCore.(B2MDBuffer in _3B15959193A57E0C1E789632BC53 3F5E).BufferProcessingResult at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/Codec.swift:582 0x560ba114f20c, partial apply forwarder for closure #1 (inout A, inout NIOCore.ByteBuffer) throws -> NIOCore.DecodingState in NIOCore.ByteToMessageHandler.(decodeLoop in _3B15959193A57E0C 1E789632BC533F5E)(context: NIOCore.ChannelHandlerContext, decodeMode: NIOCore.ByteToMessageHandler.(DecodeMode in 3B15959193A57E0C1E789632BC533F5E)) throws -> NIOCore.(B2MDBuffer in 3B15959193A57E0C1E789632BC533F5E).BufferProcessingResult at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba1146fb0, NIOCore.ByteToMessageHandler.(withNextBuffer in 3B15959193A57E0C1E789632BC533F5E)(allowEmptyBuffer: Swift.Bool, : (inout A, inout NIOCore.ByteBuffer) throws -> NIOCore.D ecodingState) throws -> NIOCore.(B2MDBuffer in _3B15959193A57E0C1E789632BC533F5E).BufferProcessingResult at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-ni o/Sources/NIOCore/Codec.swift:539 0x560ba1147b8b, NIOCore.ByteToMessageHandler.(decodeLoop in _3B15959193A57E0C1E789632BC533F5E)(context: NIOCore.ChannelHandlerContext, decodeMode: NIOCore.ByteToMessageHandler.(DecodeM ode in _3B15959193A57E0C1E789632BC533F5E)) throws -> NIOCore.(B2MDBuffer in _3B15959193A57E0C1E789632BC533F5E).BufferProcessingResult at /home/yong-yan/projects/MerlinDaemonAPISer ver/.build/checkouts/swift-nio/Sources/NIOCore/Codec.swift:578 0x560ba114952f, NIOCore.ByteToMessageHandler.channelRead(context: NIOCore.ChannelHandlerContext, data: NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.buil d/checkouts/swift-nio/Sources/NIOCore/Codec.swift:651 0x560ba1149dc8, protocol witness for NIOCore._ChannelInboundHandler.channelRead(context: NIOCore.ChannelHandlerContext, data: NIOCore.NIOAny) -> () in conformance NIOCore.ByteToMessageHandler : NIOCore._ChannelInboundHandler in NIOCore at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba1128e38, NIOCore.ChannelHandlerContext.(invokeChannelRead in _F5AC316541457BD146E3694279514AA3)(NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1702 0x560ba112d82b, NIOCore.ChannelHandlerContext.fireChannelRead(NIOCore.NIOAny) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1515 0x560ba14fea27, NIOSSL.NIOSSLHandler.(doFlushReadData in _4C55B9A85907C0CB3F4E7FBD2C1C5493)(context: NIOCore.ChannelHandlerContext, receiveBuffer: NIOCore.ByteBuffer, readOnEmptyBuffer: Swift.Bool) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio-ssl/Sources/NIOSSL/NIOSSLHandler.swift:517 0x560ba14f9cfa, NIOSSL.NIOSSLHandler.channelReadComplete(context: NIOCore.ChannelHandlerContext) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio-ssl/Sources/NIOSSL/NIOSSLHandler.swift:190 0x560ba1500540, protocol witness for NIOCore._ChannelInboundHandler.channelReadComplete(context: NIOCore.ChannelHandlerContext) -> () in conformance NIOSSL.NIOSSLHandler : NIOCore._ChannelInboundHandler in NIOSSL at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba1128f9f, NIOCore.ChannelHandlerContext.(invokeChannelReadComplete in _F5AC316541457BD146E3694279514AA3)() -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1712 0x560ba11257e9, NIOCore.ChannelPipeline.(fireChannelReadComplete0 in _F5AC316541457BD146E3694279514AA3)() -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:903 0x560ba112b47c, NIOCore.ChannelPipeline.SynchronousOperations.fireChannelReadComplete() -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOCore/ChannelPipeline.swift:1170 0x560ba140cf37, NIOPosix.BaseSocketChannel.(readable0 in _7F4F544BB68CD2CFABA0C7990D6EB2C6)() -> NIOPosix.BaseSocketChannel.(ReadStreamState in 7F4F544BB68CD2CFABA0C7990D6EB2C6) at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/BaseSocketChannel.swift:1144 0x560ba140df50, NIOPosix.BaseSocketChannel.readable() -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/BaseSocketChannel.swift:1071 0x560ba140f158, protocol witness for NIOPosix.SelectableChannel.readable() -> () in conformance NIOPosix.BaseSocketChannel : NIOPosix.SelectableChannel in NIOPosix at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba148f37e, NIOPosix.SelectableEventLoop.handleEvent(: NIOPosix.SelectorEventSet, channel: A) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:394 0x560ba1490bea, closure #2 (NIOPosix.SelectorEvent) -> () in closure #2 () throws -> () in NIOPosix.SelectableEventLoop.run() throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:469 0x560ba149542e, partial apply forwarder for closure #2 (NIOPosix.SelectorEvent) -> () in closure #2 () throws -> () in NIOPosix.SelectableEventLoop.run() throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba1498fc9, NIOPosix.Selector.whenReady0(strategy: NIOPosix.SelectorStrategy, onLoopBegin: () -> (), : (NIOPosix.SelectorEvent) throws -> ()) throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectorEpoll.swift:252 0x560ba149fcf3, NIOPosix.Selector.whenReady(strategy: NIOPosix.SelectorStrategy, onLoopBegin: () -> (), : (NIOPosix.SelectorEvent) throws -> ()) throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectorGeneric.swift:288 0x560ba149087d, closure #2 () throws -> () in NIOPosix.SelectableEventLoop.run() throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:461 0x560ba14941f3, partial apply forwarder for closure #2 () throws -> () in NIOPosix.SelectableEventLoop.run() throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba148a7e1, NIOPosix.withAutoReleasePool(() throws -> A) throws -> A at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:29 0x560ba148f78f, NIOPosix.SelectableEventLoop.run() throws -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/SelectableEventLoop.swift:460 0x560ba1447526, static NIOPosix.MultiThreadedEventLoopGroup.(runTheLoop in C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(thread: NIOPosix.NIOThread, parentGroup: Swift.Optional, canEventLoopBeShutdownIndividually: Swift.Bool, selectorFactory: () throws -> NIOPosix.Selector, initializer: (NIOPosix.NIOThread) -> (), : (NIOPosix.SelectableEventLoop) -> ()) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:95 0x560ba1447c0c, closure #1 (NIOPosix.NIOThread) -> () in static NIOPosix.MultiThreadedEventLoopGroup.(setupThreadAndEventLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(name: Swift.String, parentGroup: NIOPosix.MultiThreadedEventLoopGroup, selectorFactory: () throws -> NIOPosix.Selector, initializer: (NIOPosix.NIOThread) -> ()) -> NIOPosix.SelectableEventLoop at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/MultiThreadedEventLoopGroup.swift:116 0x560ba144d3eb, partial apply forwarder for closure #1 (NIOPosix.NIOThread) -> () in static NIOPosix.MultiThreadedEventLoopGroup.(setupThreadAndEventLoop in _C2B1528F4FBA68A3DBFA89DBAEBE9D4D)(name: Swift.String, parentGroup: NIOPosix.MultiThreadedEventLoopGroup, selectorFactory: () throws -> NIOPosix.Selector, initializer: (NIOPosix.NIOThread) -> ()) -> NIOPosix.SelectableEventLoop at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba14c8b1e, reabstraction thunk helper from @escaping @callee_guaranteed (@guaranteed NIOPosix.NIOThread) -> () to @escaping @callee_guaranteed (@in_guaranteed NIOPosix.NIOThread) -> (@out ()) at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x560ba14cb651, closure #1 (Swift.Optional) -> Swift.Optional in static NIOPosix.ThreadOpsPosix.run(handle: inout Swift.Optional, args: NIOPosix.Box<(body: (NIOPosix.NIOThread) -> (), name: Swift.Optional)>, detachThread: Swift.Bool) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/.build/checkouts/swift-nio/Sources/NIOPosix/ThreadPosix.swift:105 0x560ba14cb758, @objc closure #1 (Swift.Optional) -> Swift.Optional in static NIOPosix.ThreadOpsPosix.run(handle: inout Swift.Optional, args: NIOPosix.Box<(body: (NIOPosix.NIOThread) -> (), name: Swift.Optional)>, detachThread: Swift.Bool) -> () at /home/yong-yan/projects/MerlinDaemonAPIServer/:0 0x7f78fb6cab42 0x7f78fb75c9ff 0xffffffffffffffff Server 'myserver' crashed with exit code 132. Respawning..

To Reproduce

Currently uncertain but appears to occur randomly during the execution of a select statement.

Expected behavior

No crash should occur.

Environment

Versions: dependencies: [ // 💧 A server-side Swift web framework. .package(url: "https://github.com/vapor/fluent.git", from: "4.7.1"), .package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.2.0"), .package(url: "https://github.com/vapor/vapor.git", from: "4.75.0") ],

Swift version 5.7.1 (swift-5.7.1-RELEASE)

Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy

Additional context

Similar or identical to https://github.com/vapor/mysql-nio/issues/8

0xTim commented 1 year ago

@yong-ya what version of MySQL are you connecting to?

gwynne commented 1 year ago

This is a duplicate of #87

yong-ya commented 1 year ago

@yong-ya what version of MySQL are you connecting to?

mysql Ver 8.0.31-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

ZhangHaoKun91 commented 1 year ago

Is there any way to temporarily avoid this problem? Or which version of MySQL does not encounter this issue?

gwynne commented 1 year ago

@ZhangHaoKun91 This should have been fixed by #95, which was released in MySQLNIO version 1.6.1. Are you still seeing the problem?

ZhangHaoKun91 commented 1 year ago

@gwynne Thank you very much for your reply. My MySQL nio version is still 15.0 and I need to update it. Thank you very much.

oprisk commented 1 year ago

I'm having the same issue. SPM pulls version 1.5 from Github, not the latest 1.6.1 Any suggestion: How to override the version 1.5 to 1.6.1 effectively without override of all packages? I deleted the SPM directory and package.resolved, with the same 1.5 pulled

gwynne commented 1 year ago

@oprisk I've seen that happen when SwiftPM's configuration gets wedged. An easy way to force it is to just add the explicit dependency to your Package.swift with the version, which will either force the update (at which point you should be able to remove the extra dependency) or make it give more details about why it's not pulling the latest:

.package(url: "https://github.com/vapor/mysql-nio.git", from: "1.6.1"),
oprisk commented 1 year ago

Thanks, will update if the same issue persists. info: pulls mysql-nio version 1.7.0