vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
305 stars 70 forks source link

Fix Segmentation faults in Swift 5.8 #406

Closed fabianfett closed 10 months ago

fabianfett commented 10 months ago

Code to replicate issue #405.

The repro crashes in 5.8.1 after 100 iterations:

Backtrace

    frame #0: 0x0000fffff696c584 libc.so.6`___lldb_unnamed_symbol3383 + 1348
libc.so.6`___lldb_unnamed_symbol3383:
->  0xfffff696c584 <+1348>: ldr    x8, [x6, #0x10]
    0xfffff696c588 <+1352>: cmp    x8, x2
    0xfffff696c58c <+1356>: b.ne   0xfffff696c888            ; <+2120>
    0xfffff696c590 <+1360>: ldr    x8, [x2, #0x10]
Target 0: (Repro) stopped.
(lldb) bt
* thread #2, name = 'NIO-ELT-0-#0', stop reason = signal SIGSEGV: invalid address (fault address: 0xfffdf00000a0)
  * frame #0: 0x0000fffff696c584 libc.so.6`___lldb_unnamed_symbol3383 + 1348
    frame #1: 0x0000fffff696e548 libc.so.6`__libc_calloc + 216
    frame #2: 0x0000fffff75c05b8 libdispatch.so`_dispatch_continuation_alloc_from_heap + 20
    frame #3: 0x0000fffff75d2b88 libdispatch.so`_dispatch_continuation_redirect_push + 316
    frame #4: 0x0000fffff7336690 libswift_Concurrency.so`resumeTaskAfterContinuation(swift::AsyncTask*, swift::ContinuationAsyncContext*) + 380
    frame #5: 0x0000aaaaaace1358 Repro`partial apply for specialized closure #1 in closure #1 in EventLoopFuture.get() at <compiler-generated>:0 [opt]
    frame #6: 0x0000aaaaaad1be70 Repro`merged generic specialization <()> of closure #1 @Sendable () -> NIOCore.CallbackList in NIOCore.EventLoopFuture._publicWhenComplete(@Sendable (Swift.Result<τ_0_0, Swift.Error>) -> ()) -> () + 92
    frame #7: 0x0000aaaaaad1bd94 Repro`merged generic specialization <()> of closure #1 @Sendable () -> () in NIOCore.EventLoopFuture._internalWhenComplete(@Sendable () -> NIOCore.CallbackList) -> () + 68
    frame #8: 0x0000aaaaaadc1390 Repro`SelectableEventLoop.run() [inlined] closure #4 () -> () in NIOPosix.SelectableEventLoop.run() throws -> () at SelectableEventLoop.swift:518:30 [opt]
    frame #9: 0x0000aaaaaadc138c Repro`SelectableEventLoop.run() [inlined] generic specialization <()> of NIOPosix.withAutoReleasePool<τ_0_0>(() throws -> τ_0_0) throws -> τ_0_0 at SelectableEventLoop.swift:29:16 [opt]
    frame #10: 0x0000aaaaaadc138c Repro`SelectableEventLoop.run(self=0x0000fffff0001170) at SelectableEventLoop.swift:517:21 [opt]
    frame #11: 0x0000aaaaaada60fc Repro`closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) at MultiThreadedEventLoopGroup.swift:97:22 [opt]
    frame #12: 0x0000aaaaaada60d8 Repro`closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(t=<unavailable>, parentGroup=<unavailable>, selectorFactory=0x0000aaaaaada631c Repro`implicit closure #1 () throws -> NIOPosix.Selector<NIOPosix.NIORegistration> in NIOPosix.MultiThreadedEventLoopGroup.init(numberOfThreads: Swift.Int) -> NIOPosix.MultiThreadedEventLoopGroup, initializer=<unavailable>, lock=NIOConcurrencyHelpers.NIOLock @ x19, loopUpAndRunningGroup=0x0000aaaaab16d7c0) at MultiThreadedEventLoopGroup.swift:118:41 [opt]
    frame #13: 0x0000aaaaaada8d64 Repro`partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:parentGroup:selectorFactory:initializer:) at <compiler-generated>:0 [opt]
    frame #14: 0x0000aaaaaadaab38 Repro`thunk for @escaping @callee_guaranteed (@guaranteed NIOThread) -> () at <compiler-generated>:0 [opt]
    frame #15: 0x0000aaaaaaddbe2c Repro`closure #1 in static ThreadOpsPosix.run($0=0xaaaaab16d950) at ThreadPosix.swift:112:13 [opt]
    frame #16: 0x0000fffff695d5c8 libc.so.6`___lldb_unnamed_symbol3291 + 724
    frame #17: 0x0000fffff69c5d1c libc.so.6`___lldb_unnamed_symbol3659 + 12
codecov-commenter commented 10 months ago

Codecov Report

Merging #406 (8f9a39d) into main (d89a723) will decrease coverage by 0.13%. The diff coverage is n/a.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #406 +/- ## ========================================== - Coverage 49.13% 49.01% -0.13% ========================================== Files 108 108 Lines 8841 8841 ========================================== - Hits 4344 4333 -11 - Misses 4497 4508 +11 ``` [see 2 files with indirect coverage changes](https://app.codecov.io/gh/vapor/postgres-nio/pull/406/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor)