Well, you need to analysis the packets carefully, it's the client actively closed the connection.(192.168.20.108.52683 > ***.80). In fact, curl always closes the connection immediately.
On Wednesday, June 21, 2017 at 10:15:21 AM UTC+8, Chen Wang wrote:
Hi everybody,
I built a server with CentOS based on openresty recently, and yesterday i found a strange problem about keepalive configuation.
In the beginning, i read access.log, then find there is an api used Alamofire to access that its request_time always be 5s, but its service process time is about 1s.
but, when i use curl or PC to access, its request_time is less than 1s.
use tcpdump to analysis,
19:38:26.145110 IP (tos 0x0, ttl 64, id 52263, offset 0, flags [DF], proto TCP (6), length 64, bad cksum 0 (->15db)!)
192.168.20.108.52683 > ***.80: Flags [S], cksum 0x58e8 (incorrect -> 0xb218), seq 3832367445, win 65535, options [mss 1460,nop,wscale 5,nop,nop,TS val 213918608 ecr 0,sackOK,eol], length 0
19:38:26.178794 IP (tos 0x0, ttl 47, id 0, offset 0, flags [DF], proto TCP (6), length 52)
***.80 > 192.168.20.108.52683: Flags [S.], cksum 0x0b29 (correct), seq 27251865, ack 3832367446, win 14600, options [mss 1460,nop,nop,sackOK,nop,wscale 9], length 0
19:38:26.178945 IP (tos 0x0, ttl 64, id 46472, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->2c92)!)
192.168.20.108.52683 > ***.80: Flags [.], cksum 0x58d0 (incorrect -> 0x6505), seq 1, ack 1, win 8192, length 0
19:38:26.181087 IP (tos 0x0, ttl 64, id 17372, offset 0, flags [DF], proto TCP (6), length 603, bad cksum 0 (->9c0b)!)
192.168.20.108.52683 > ***.80: Flags [P.], cksum 0x5b03 (incorrect -> 0x4c8b), seq 1:564, ack 1, win 8192, length 563: HTTP, length: 563
GET /friend/getFriendList?client_name=**_ios_***&client_sequence=0&client_version=1.0.0&r=1497958706&uid=604455751 HTTP/1.1
Content-Type: application/json
Accept: application/json;version=1.0
User-Agent: FileMail/1.0.1 (com.xlvip.FileMail; build:4; iOS 10.3.0) Alamofire/4.5.0
Authorization: Basic NjA0NDU1NzUxOmNzMDAxLkI3NjhFNjA2OUVGRkQxQkI5MDhGM0MwQUFBOEM2NDg3OmNsaWVudDoyMDAyMg==
Accept-Language: zh-Hans-US;q=1.0, en;q=0.9
Accept-Encoding: gzip;q=1.0, compress;q=0.5
19:38:26.214914 IP (tos 0x0, ttl 47, id 57980, offset 0, flags [DF], proto TCP (6), length 40)
***.80 > 192.168.20.108.52683: Flags [.], cksum 0x82b3 (correct), seq 1, ack 564, win 31, length 0
19:38:26.504987 IP (tos 0x0, ttl 47, id 57981, offset 0, flags [DF], proto TCP (6), length 791)
***.80 > 192.168.20.108.52683: Flags [P.], cksum 0x96f1 (correct), seq 1:752, ack 564, win 31, length 751: HTTP, length: 751
Date: Tue, 20 Jun 2017 11:38:26 GMT
Expires: Wed, 21 Jun 2017 11:38:26 GMT
Cache-Control: max-age=86400
19:38:26.505098 IP (tos 0x0, ttl 64, id 45888, offset 0, flags [DF], proto TCP (6), length 40, bad cksum 0 (->2eda)!)
192.168.20.108.52683 > ***.80: Flags [.], cksum 0x58d0 (incorrect -> 0x5ffb), seq 564, ack 752, win 8168, length 0
19:38:31.507882 IP (tos 0x0, ttl 47, id 57982, offset 0, flags [DF], proto TCP (6), length 40)
***.80 > 192.168.20.108.52683: Flags [R.], cksum 0x7fc0 (correct), seq 752, ack 564, win 31, length 0
in nginx.conf, i set keepalive_timeout = 60, but in the log server disconnet to client at last, it is very strange.
and when i set keepalive_time = 0, everything is ok, Alamofire request_time back to 1s.