2017-07-14 63 views
0

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

[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: /

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

我现在唯一的解决方案是重新启动服务器。从哪个角度来看问题不会立即发生。

想法?

回答

0

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