運維發現服務器有大量鏈接不釋放,並且每次app訪問都會創建新鏈接。html
netstat -antlp |grep ESTAB|grep 8080|wc -l (訪問服務器8080端口的已創建的鏈接數)web
後來用瀏覽器測試沒問題。接着發現終端鏈接時,設置了http header: Connection: keep-alive 。可是一樣用postman模擬,也沒問題。最終發現應該是app寫了keepalive,鏈接調用時確沒有用之前打開的鏈接,而是新建一個鏈接。json
而服務器端wildfly默認打開了keepalive,並且永遠不會超時。wildfy的undertow添加keepalive超時設置以下:ms瀏覽器
<http-listener name="default" max-post-size="204857600" socket-binding="http" redirect-socket="https" tcp-keep-alive="true" read-timeout="30000"/>bash
用telnet模擬http 客戶端調用,能夠看到當服務器返回內容後,鏈接並無斷開,直到超時。服務器
以下示例在一個打開的鏈接裏面,作了兩次post。app
>telnet 211.100.75.241 8080 Trying 211.100.75.241... Connected to 211.100.75.241. Escape character is '^]'. POST /Message/update HTTP/1.1 Host: 211.100.75.241:8080 Connection: keep-alive Content-Length: 31 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: null Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5702.400 QQBrowser/10.2.1893.400 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 DNT: 1 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 mac=00%3A07%3A63%3Ae2%3Aa7%3A62 HTTP/1.1 200 OK Connection: keep-alive X-Powered-By: Undertow/1 Server: WildFly/10 Content-Type: application/json;charset=UTF-8 Content-Length: 1 Date: Mon, 06 Aug 2018 08:48:58 GMT POST /Message/update HTTP/1.1 Host: 211.100.75.241:8080 Connection: keep-alive Content-Length: 31 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: null Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5702.400 QQBrowser/10.2.1893.400 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 DNT: 1 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 mac=00%3A07%3A63%3Ae2%3Aa7%3A62 HTTP/1.1 200 OK Connection: keep-alive X-Powered-By: Undertow/1 Server: WildFly/10 Content-Type: application/json;charset=UTF-8 Content-Length: 1 Date: Mon, 06 Aug 2018 08:49:05 GMT Connection closed by foreign host.