             .childChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
             .childChannelOption(ChannelOptions.maxMessagesPerRead, value: 16)
             .childChannelOption(ChannelOptions.recvAllocator, value: AdaptiveRecvByteBufferAllocator())
-        defer {
-            try! group.syncShutdownGracefully()
-        }
 
         channel = try! bootstrap.bind(to: SocketAddress(ipAddress: "0.0.0.0", port: UInt16(port))).wait()
         channel6 = try! bootstrap.bind(to: SocketAddress(ipAddress: "::", port: UInt16(port))).wait()

                channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).then {
                    // It's important we use the same handler for all accepted channels. The ControllerHandler is thread-safe!
                    channel.pipeline.add(handler: device.controllerHandler!).then {
                        channel.pipeline.add(handler: RequestHandler()).then {
                            channel.pipeline.add(handler: applicationHandler)
                        }
                    }
                }

        updateDiscoveryRecord()

        service.publish(options: NetService.Options(rawValue: 0))
    }

    public func wait() {
        try! channel.closeFuture.wait()
        try! channel6.closeFuture.wait()

        defer {
            try! group.syncShutdownGracefully()
        }
    }

    /// Publish the Accessory configuration on the Bonjour service
