Repository: vapor/vapor
File: Sources/Vapor/Server/NIOServer.swift (Swift)

Code before:
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Server.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> NIOServer {
        return try NIOServer(config: container.make(), container: container)
    }

    /// Chosen configuration for this server.
    public let config: NIOServerConfig

    /// Container for setting on event loops.
    public fileprivate(set) weak var container: Container!
    
    /// Hold the current worker. Used for deinit.    
    private var currentWorker: Worker?

    /// Create a new `NIOServer`.
    ///
    /// - parameters:
    ///     - config: Server preferences such as hostname, port, max body size, etc.
    ///     - container: Root service-container to use for all event loops the server will create.
    public init(config: NIOServerConfig, container: Container) {
        self.config = config
        self.container = container
        self.currentWorker = container
    }

    /// See `Server`.
    public func start(hostname: String?, port: Int?) -> Future<Void> {
        do {
            // console + logger required for outputting messages and error info
            let console = try container.make(Console.self)
            let logger = try container.make(Logger.self)

            // determine which hostname / port to bind to
            let hostname = hostname ?? config.hostname
            let port = port ?? config.port

            // print starting message
            console.print("Server starting on ", newLine: false)
            console.output("http://" + hostname, style: .init(color: .cyan), newLine: false)
            console.output(":" + port.description, style: .init(color: .cyan))

            // create caches
            let containerCache = ThreadSpecificVariable<ThreadContainer>()
            let responderCache = ThreadSpecificVariable<ThreadResponder>()

            // create this server's own event loop group
            let group = MultiThreadedEventLoopGroup(numberOfThreads: config.workerCount)
            for _ in 0..<config.workerCount {

Review comment (suggestion):
This should be set to the event loop group created during boot.

https://github.com/vapor/vapor/blob/6c8c17557dd081c669a65031548a42da74072ab5/Sources/Vapor/Server/NIOServer.swift#L52

As long as the `Container` here (actually an Application) is not being held onto strongly, the application will deinit and shutdown its own ELG. The server is only responsible for not creating a reference cycle to application and shutting down the ELG that it creates.

Code after:
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Server.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> NIOServer {
        return try NIOServer(config: container.make(), container: container)
    }

    /// Chosen configuration for this server.
    public let config: NIOServerConfig

    /// Container for setting on event loops.
    public fileprivate(set) weak var container: Container!

    /// Hold the current worker. Used for deinit.
    private var currentWorker: Worker?

    /// Create a new `NIOServer`.
    ///
    /// - parameters:
    ///     - config: Server preferences such as hostname, port, max body size, etc.
    ///     - container: Root service-container to use for all event loops the server will create.
    public init(config: NIOServerConfig, container: Container) {
        self.config = config
        self.container = container
    }

    /// See `Server`.
    public func start(hostname: String?, port: Int?) -> Future<Void> {
        do {
            // console + logger required for outputting messages and error info
            let console = try container.make(Console.self)
            let logger = try container.make(Logger.self)

            // determine which hostname / port to bind to
            let hostname = hostname ?? config.hostname
            let port = port ?? config.port

            // print starting message
            console.print("Server starting on ", newLine: false)
            console.output("http://" + hostname, style: .init(color: .cyan), newLine: false)
            console.output(":" + port.description, style: .init(color: .cyan))

            // create caches
            let containerCache = ThreadSpecificVariable<ThreadContainer>()
            let responderCache = ThreadSpecificVariable<ThreadResponder>()

            // create this server's own event loop group
            let group = MultiThreadedEventLoopGroup(numberOfThreads: config.workerCount)
            self.currentWorker = group
            for _ in 0..<config.workerCount {