One of the HTTP delayed upgrade tests occasionally fails with the following backtrace:
* thread #7, name = 'NIO-ELT-#0', stop reason = Fatal error: Can't remove last element from an empty collection
frame #0: 0x00000001094ff100 libswiftCore.dylib`_swift_runtime_on_report
frame #1: 0x0000000109542bb1 libswiftCore.dylib`_swift_stdlib_reportFatalError + 113
frame #2: 0x0000000109273d66 libswiftCore.dylib`function signature specialization <Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <()> of Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A + 54
frame #3: 0x00000001094e3df3 libswiftCore.dylib`partial apply forwarder for closure #2 (Swift.UnsafeBufferPointer<Swift.UInt8>) -> () in Swift._fatalErrorMessage(Swift.StaticString, Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 99
frame #4: 0x0000000109273d66 libswiftCore.dylib`function signature specialization <Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_guaranteed (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <()> of Swift.StaticString.withUTF8Buffer<A>((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A + 54
frame #5: 0x00000001093fbfb0 libswiftCore.dylib`function signature specialization <Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage(Swift.StaticString, Swift.StaticString, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 96
frame #6: 0x0000000109368d8e libswiftCore.dylib`merged (extension in Swift):Swift.RangeReplaceableCollection< where A: Swift.BidirectionalCollection>.removeLast() -> A.Element + 526
frame #7: 0x0000000109270dd0 libswiftCore.dylib`(extension in Swift):Swift.RangeReplaceableCollection< where A: Swift.BidirectionalCollection>.removeLast() -> A.Element + 16
frame #8: 0x000000010438016d NIOHTTP1Tests`implicit closure #4 in assertResponseIs(lines=0x000070000f838f80) at HTTPUpgradeTests.swift:91
frame #9: 0x00000001043a04e7 NIOHTTP1Tests`partial apply for implicit closure #4 in assertResponseIs(response:expectedResponseLine:expectedResponseHeaders:) at HTTPUpgradeTests.swift:0
frame #10: 0x000000010431a67a NIOHTTP1Tests`thunk for @callee_guaranteed () -> (@owned String, @error @owned Error) at HTTPHeadersTest.swift:0
frame #11: 0x00000001043a054b NIOHTTP1Tests`thunk for @callee_guaranteed () -> (@owned String, @error @owned Error)partial apply at HTTPUpgradeTests.swift:0
frame #12: 0x0000000109c484f2 libswiftXCTest.dylib`merged closure #1 () throws -> () in XCTest.XCTAssertEqual<A where A: Swift.Equatable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 162
frame #13: 0x0000000109c550da libswiftXCTest.dylib`merged partial apply forwarder for closure #1 () throws -> () in XCTest.XCTAssertGreaterThan<A where A: Swift.Comparable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 42
frame #14: 0x0000000109c55247 libswiftXCTest.dylib`partial apply forwarder for closure #1 () throws -> () in XCTest.XCTAssertEqual<A where A: Swift.Equatable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 23
frame #15: 0x0000000109c54f1b libswiftXCTest.dylib`partial apply forwarder for closure #1 () -> () in XCTest._XCTRunThrowableBlock(() throws -> ()) -> XCTest._XCTThrowableBlockResult + 27
frame #16: 0x0000000109c4794e libswiftXCTest.dylib`reabstraction thunk helper from @callee_guaranteed () -> () to @callee_unowned @convention(block) () -> () + 14
frame #17: 0x0000000109c5577e libswiftXCTest.dylib`_XCTRunThrowableBlockBridge + 14
frame #18: 0x0000000109c48deb libswiftXCTest.dylib`function signature specialization <Arg[0] = Owned To Guaranteed> of XCTest._XCTRunThrowableBlock(() throws -> ()) -> XCTest._XCTThrowableBlockResult + 203
frame #19: 0x0000000109c4c575 libswiftXCTest.dylib`function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed, Arg[2] = Owned To Guaranteed, Arg[3] = Exploded> of XCTest.XCTAssertEqual<A where A: Swift.Equatable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 325
frame #20: 0x0000000109c485e9 libswiftXCTest.dylib`merged XCTest.XCTAssertEqual<A where A: Swift.Equatable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 41
frame #21: 0x0000000109c47c51 libswiftXCTest.dylib`XCTest.XCTAssertEqual<A where A: Swift.Equatable>(@autoclosure () throws -> A, @autoclosure () throws -> A, @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 81
frame #22: 0x000000010437f5cf NIOHTTP1Tests`assertResponseIs(response="", expectedResponseLine="HTTP/1.1 101 Switching Protocols", expectedResponseHeaders=3 values) at HTTPUpgradeTests.swift:91
* frame #23: 0x0000000104399ab6 NIOHTTP1Tests`closure #2 in HTTPUpgradeTestCase.testDelayedUpgradeBehaviour(buffers=0 values, completePromise=NIO.EventLoopPromise<Swift.Void> @ 0x000070000f8390e0) at HTTPUpgradeTests.swift:658
frame #24: 0x0000000104399b4d NIOHTTP1Tests`partial apply for closure #2 in HTTPUpgradeTestCase.testDelayedUpgradeBehaviour() at HTTPUpgradeTests.swift:0
frame #25: 0x000000010434d270 NIOHTTP1Tests`closure #1 in ArrayAccumulationHandler.init(completion=0x0000000104399b40 NIOHTTP1Tests`partial apply forwarder for closure #2 (Swift.Array<NIO.ByteBuffer>) -> () in NIOHTTP1Tests.HTTPUpgradeTestCase.testDelayedUpgradeBehaviour() throws -> () at HTTPUpgradeTests.swift, self=0x000000010234efa0) at HTTPServerClientTest.swift:58
frame #26: 0x000000010434d314 NIOHTTP1Tests`partial apply for closure #1 in ArrayAccumulationHandler.init(completion:) at HTTPServerClientTest.swift:0
frame #27: 0x000000010434d34d NIOHTTP1Tests`thunk for @escaping @callee_guaranteed () -> () at HTTPServerClientTest.swift:0
frame #28: 0x00007fff5a4fc0c9 libdispatch.dylib`_dispatch_client_callout + 8
frame #29: 0x00007fff5a50ca2f libdispatch.dylib`_dispatch_block_invoke_direct + 294
frame #30: 0x000000010434d91f NIOHTTP1Tests`ArrayAccumulationHandler.channelUnregistered(ctx=0x00000001027d2170, self=0x000000010234efa0) at HTTPServerClientTest.swift:67
frame #31: 0x000000010434dc51 NIOHTTP1Tests`protocol witness for _ChannelInboundHandler.channelUnregistered(ctx:) in conformance ArrayAccumulationHandler<A> at HTTPServerClientTest.swift:0
frame #32: 0x0000000104599b20 NIO`ChannelHandlerContext.invokeChannelUnregistered(self=0x00000001027d2170) at ChannelPipeline.swift:1028
frame #33: 0x00000001045932de NIO`ChannelPipeline.fireChannelUnregistered0(self=0x0000000102608b30) at ChannelPipeline.swift:615
frame #34: 0x000000010462ea30 NIO`BaseSocketChannel.close0(error=alreadyClosed, mode=all, promise=nil, self=0x00000001026084a0) at SocketChannel.swift:495
frame #35: 0x00000001046376a4 NIO`SocketChannel.close0(error=alreadyClosed, mode=all, promise=nil, self=0x00000001026084a0) at SocketChannel.swift:929
frame #36: 0x0000000104632047 NIO`protocol witness for ChannelCore.close0(error:mode:promise:) in conformance BaseSocketChannel<A> at SocketChannel.swift:0
frame #37: 0x000000010459cbc9 NIO`HeadChannelHandler.close(ctx=0x0000000102608b80, mode=all, promise=nil, self=0x000000010279ec00) at ChannelPipeline.swift:707
frame #38: 0x000000010459cf2f NIO`protocol witness for _ChannelOutboundHandler.close(ctx:mode:promise:) in conformance HeadChannelHandler at ChannelPipeline.swift:0
frame #39: 0x0000000104596611 NIO`ChannelHandlerContext.invokeClose(mode=all, promise=nil, self=0x0000000102608b80) at ChannelPipeline.swift:1189
frame #40: 0x00000001045966cb NIO`ChannelHandlerContext.invokeClose(mode=all, promise=nil, self=0x00000001027d2170) at ChannelPipeline.swift:1191
frame #41: 0x00000001045943f2 NIO`ChannelPipeline.close0(mode=all, promise=nil, self=0x0000000102608b30) at ChannelPipeline.swift:541
frame #42: 0x00000001045944fe NIO`closure #1 in ChannelPipeline.close(self=0x0000000102608b30, mode=all, promise=nil) at ChannelPipeline.swift:444
frame #43: 0x000000010459b245 NIO`partial apply for closure #1 in ChannelPipeline.close(mode:promise:) at ChannelPipeline.swift:0
frame #44: 0x0000000104561cfc NIO`thunk for @escaping @callee_guaranteed () -> () at Bootstrap.swift:0
frame #45: 0x00000001045bba81 NIO`partial apply for thunk for @escaping @callee_guaranteed () -> () at EventLoop.swift:0
frame #46: 0x00000001045bb827 NIO`thunk for @escaping @callee_guaranteed (@in ()) -> (@out ()) at EventLoop.swift:0
frame #47: 0x00000001045bba21 NIO`thunk for @escaping @callee_guaranteed (@in ()) -> (@out ())partial apply at EventLoop.swift:0
frame #48: 0x00000001045bb847 NIO`closure #2 in SelectableEventLoop.run(task=0x00000001045bba10 NIO`reabstraction thunk helper from @escaping @callee_guaranteed (@in ()) -> (@out ()) to @escaping @callee_guaranteed () -> ()partial apply forwarder with unmangled suffix ".57" at EventLoop.swift) at EventLoop.swift:527
frame #49: 0x00000001045bb8a1 NIO`partial apply for closure #2 in SelectableEventLoop.run() at EventLoop.swift:0
frame #50: 0x0000000104558da6 NIO`thunk for @callee_guaranteed () -> (@error @owned Error) at BlockingIOThreadPool.swift:0
frame #51: 0x00000001045bb90b NIO`thunk for @callee_guaranteed () -> (@error @owned Error)partial apply at EventLoop.swift:0
frame #52: 0x00000001045b5eb2 NIO`closure #1 in withAutoReleasePool<A>(execute=0x00000001045bb8f0 NIO`reabstraction thunk helper from @callee_guaranteed () -> (@error @owned Swift.Error) to @callee_guaranteed () -> (@out (), @error @owned Swift.Error)partial apply forwarder with unmangled suffix ".50" at EventLoop.swift) at EventLoop.swift:261
frame #53: 0x00000001045c33f6 NIO`partial apply for closure #1 in withAutoReleasePool<A>(_:) at EventLoop.swift:0
frame #54: 0x0000000109bb687f libswiftObjectiveC.dylib`ObjectiveC.autoreleasepool<A>(invoking: () throws -> A) throws -> A + 47
frame #55: 0x00000001045b5e28 NIO`withAutoReleasePool<A>(execute=0x00000001045bb8f0 NIO`reabstraction thunk helper from @callee_guaranteed () -> (@error @owned Swift.Error) to @callee_guaranteed () -> (@out (), @error @owned Swift.Error)partial apply forwarder with unmangled suffix ".50" at EventLoop.swift) at EventLoop.swift:260
frame #56: 0x00000001045bada2 NIO`SelectableEventLoop.run(self=0x00000001027d10c0) at EventLoop.swift:526
frame #57: 0x00000001045bdedf NIO`closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(t=(pthread = 0x000070000f83b000), initializer=0x00000001045c2e30 NIO`partial apply forwarder for reabstraction thunk helper from @escaping @callee_guaranteed (@in NIO.Thread) -> (@out ()) to @escaping @callee_guaranteed (@owned NIO.Thread) -> () at EventLoop.swift, lock=(mutex = 0x0000000109d38ff0), _loop=0x00000001027d10c0, loopUpAndRunningGroup=0x0000000109d38e50) at EventLoop.swift:666
frame #58: 0x00000001045c2f0d NIO`partial apply for closure #1 in static MultiThreadedEventLoopGroup.setupThreadAndEventLoop(name:initializer:) at EventLoop.swift:0
frame #59: 0x00000001045be48f NIO`thunk for @escaping @callee_guaranteed (@owned Thread) -> () at EventLoop.swift:0
frame #60: 0x000000010464cca1 NIO`partial apply for thunk for @escaping @callee_guaranteed (@owned Thread) -> () at Thread.swift:0
frame #61: 0x000000010464bcf8 NIO`closure #1 in static Thread.spawnAndRun(p=(_rawValue = 0x0000000109d37040 -> 0x00000001095b86a0 libswiftCore.dylib`InitialAllocationPool + 13968)) at Thread.swift:105
frame #62: 0x000000010464bd79 NIO`@objc closure #1 in static Thread.spawnAndRun(name:body:) at Thread.swift:0
frame #63: 0x00007fff5a851642 libsystem_pthread.dylib`_pthread_body + 126
frame #64: 0x00007fff5a8515c4 libsystem_pthread.dylib`_pthread_start + 61
frame #65: 0x00007fff5a851229 libsystem_pthread.dylib`thread_start + 13
We should investigate why this is happening, but it seems to just be a problem in the test code itself: probably a race.