为什么Swift Kitura服务器没有终止某些线程?

时间:2017-07-14 03:50:17

标签: swift kitura

我正在运行的Swift服务器上有一个可重现的问题。这是一个使用Kitura的多线程服务器。基础知识是:服务器运行一段时间后,下载请求开始需要从客户端重试(通常是三次重试)。来自客户端的尝试导致服务器线程无法终止。在服务器上,下载问题在日志中显示如下:

[INFO] REQUEST /DownloadFile: ABOUT TO END ...

然后请求永远不会终止。

我服务器中的相关片段代码如下所示:

    // <snip>
    Log.info(message: "REQUEST \(request.urlURL.path): ABOUT TO END ...")

    do {
        try self.response.end()
        Log.info(message: "REQUEST \(request.urlURL.path): STATUS CODE: \(response.statusCode)")
    } catch (let error) {
        Log.error(message: "Failed on `end` in failWithError: \(error.localizedDescription); HTTP status code: \(response.statusCode)")
    }

    Log.info(message: "REQUEST \(request.urlURL.path): COMPLETED")
    // <snip>

也就是说,服务器显然似乎挂在end(Kitura方法)的调用上。另请参阅https://github.com/crspybits/SyncServerII/blob/master/Sources/Server/Setup/RequestHandler.swift#L105

在上次出现此问题之前,我在服务器日志中观察到以下内容:

[2017-07-12T15:31:23.302Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 5(0x5), ERROR: SSL_accept, code: 5, reason: DH lib
[2017-07-12T15:31:23.604Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:31:23.995Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:40:32.941Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.
[2017-07-12T15:42:43.000Z] [VERBOSE] [HTTPServerRequest.swift:215 parsingCompleted()] HTTP request from=139.162.78.135; proto=https;
[INFO] REQUEST RECEIVED: /
[2017-07-12T16:32:38.479Z] [ERROR] [HTTPServer.swift:194 listen(listenSocket:socketManager:)] Error accepting client connection: Error code: 1(0x1), ERROR: SSL_accept, code: 1, reason: Could not determine error reason.

我不确定这是从哪里来的,因为我不确定我的客户是否正在产生这个。我没有使用“/”明确向我的服务器发出请求。 (我偶尔会看到从我的服务器向我的服务器发出的请求 - 这可能就是其中之一)。请注意,除了其中一条日志消息之外的所有消息都来自Kitura,而不是直接来自我的代码。我的日志消息是[INFO] REQUEST RECEIVED: /

如果我是一个博彩人,我会说上面的错误让我的服务器进入了一个状态,之后我看到了这个下载/重试行为。

此时我唯一的解决方案是重启服务器。从那时起问题就不会立即发生。

思想?

1 个答案:

答案 0 :(得分:0)

我不确定这是否解决了根本问题,或者它是否只是一种解决方法,但似乎有效。使用问题中所述的服务器,我一直在使用Kitura的内置SSL支持。我现在已经转而使用NGINX作为前端,不再使用Kitura的内置SSL支持。 NGINX负责所有HTTPS / SSL细节。由于这样做(大约一个月前),并且服务器运行了所有这段时间,我没有遇到此问题中报告的not terminating问题。另请参阅https://github.com/crspybits/SyncServerII/issues/28