服务器监听公网ip时,调用uv_write失败
服务器调用send_bytes向客户端发数据,在满足以下两个条件时失败:
- 客户端通过公网ip连接到服务器。
- 服务器发送的数据大于一定值时(<32KB都没问题,发送100+KB或400+KB的数据就失败了)。
其它情况都能发送成功,以下是代码:
c
// libuv 是 1.x 版本 void after_send(uv_write_t *write_req, int status) { if (status != 0) { // 部署在不同机器上时,分别出现过 broken pipe 和 bad address in system call argument 这两种错误消息 mydebug("send failed: %s", uv_strerror(status)); } else { mydebug("send success"); } free(write_req); } int send_bytes(client_t *client, tCString bytes, size_t len) { uv_write_t *write_req = malloc(sizeof(*write_req)); // bytes 所指向的内存是有效的,并且始终没有 free write_req->data = (void *)bytes; uv_buf_t send_buf = { .base = (char *)bytes, .len = len }; uv_write(write_req, (uv_stream_t *)&client->handle, &send_buf, 1, after_send); return 0; }
我的问题是: 引起这个bug的可能原因是什么?
更新 :传输1MB的文件时,客户端ACK得很慢(为什么),下面是抓包的结果(只选取了部分):
tcpdump: data link type PKTAP
listening on any, link-type PKTAP (Packet Tap), capture size 65535 bytes
Seconds Port > Port
15.576708 8883 > 52630 [.] seq 1:16333 ack 306 win 9167 len 16332
15.576711 8883 > 52630 [.] seq 16333:32665 ack 306 win 9167 len 16332
15.576714 8883 > 52630 [.] seq 32665:48997 ack 306 win 9167 len 16332
15.576717 8883 > 52630 [.] seq 48997:65329 ack 306 win 9167 len 16332
15.576731 8883 > 52630 [.] seq 1:16333 ack 306 win 9167 len 16332
15.576736 8883 > 52630 [.] seq 16333:32665 ack 306 win 9167 len 16332
15.576739 8883 > 52630 [.] seq 65329:81661 ack 306 win 9167 len 16332
15.576742 8883 > 52630 [.] seq 32665:48997 ack 306 win 9167 len 16332
15.576745 8883 > 52630 [.] seq 81661:97993 ack 306 win 9167 len 16332
15.576748 8883 > 52630 [.] seq 48997:65329 ack 306 win 9167 len 16332
15.576750 8883 > 52630 [.] seq 97993:114325 ack 306 win 9167 len 16332
15.576754 8883 > 52630 [.] seq 114325:130657 ack 306 win 9167 len 16332
15.576779 52630 > 8883 [.] ack 32665 win 7145 len 0
15.576789 52630 > 8883 [.] ack 65329 win 13269 len 0
15.576791 8883 > 52630 [.] seq 65329:81661 ack 306 win 9167 len 16332
15.576795 8883 > 52630 [.] seq 81661:97993 ack 306 win 9167 len 16332
15.576800 8883 > 52630 [.] seq 97993:114325 ack 306 win 9167 len 16332
15.576803 8883 > 52630 [.] seq 114325:130657 ack 306 win 9167 len 16332
15.576807 52630 > 8883 [.] ack 32665 win 7145 len 0
15.576808 52630 > 8883 [.] ack 65329 win 13269 len 0
15.576841 8883 > 52630 [.] seq 130657:146989 ack 306 win 9167 len 16332
15.576847 8883 > 52630 [.] seq 146989:163321 ack 306 win 9167 len 16332
15.576851 8883 > 52630 [.] seq 163321:179653 ack 306 win 9167 len 16332
15.576855 8883 > 52630 [P.] seq 179653:187949 ack 306 win 9167 len 8296
15.576862 8883 > 52630 [.] seq 187949:204281 ack 306 win 9167 len 16332
15.576866 8883 > 52630 [.] seq 204281:220613 ack 306 win 9167 len 16332
15.576870 8883 > 52630 [.] seq 220613:236945 ack 306 win 9167 len 16332
15.576874 8883 > 52630 [P.] seq 236945:253277 ack 306 win 9167 len 16332
15.576879 8883 > 52630 [.] seq 130657:146989 ack 306 win 9167 len 16332
15.576883 8883 > 52630 [.] seq 146989:163321 ack 306 win 9167 len 16332
15.576887 8883 > 52630 [.] seq 163321:179653 ack 306 win 9167 len 16332
15.576891 8883 > 52630 [P.] seq 179653:187949 ack 306 win 9167 len 8296
15.576894 8883 > 52630 [.] seq 187949:204281 ack 306 win 9167 len 16332
15.576898 8883 > 52630 [.] seq 204281:220613 ack 306 win 9167 len 16332
15.576901 8883 > 52630 [.] seq 220613:236945 ack 306 win 9167 len 16332
15.576905 8883 > 52630 [P.] seq 236945:253277 ack 306 win 9167 len 16332
15.947181 8883 > 52630 [.] seq 65329:81661 ack 306 win 9167 len 16332
15.947222 8883 > 52630 [.] seq 65329:81661 ack 306 win 9167 len 16332
16.350140 8883 > 52630 [.] seq 65329:66517 ack 306 win 9167 len 1188
16.350151 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
16.350156 8883 > 52630 [.] seq 67705:68893 ack 306 win 9167 len 1188
16.350161 8883 > 52630 [.] seq 68893:70081 ack 306 win 9167 len 1188
16.350165 8883 > 52630 [.] seq 65329:66517 ack 306 win 9167 len 1188
16.350167 8883 > 52630 [.] seq 70081:71269 ack 306 win 9167 len 1188
16.350170 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
16.350173 8883 > 52630 [.] seq 71269:72457 ack 306 win 9167 len 1188
16.350189 8883 > 52630 [.] seq 72457:73645 ack 306 win 9167 len 1188
16.350194 8883 > 52630 [.] seq 73645:74833 ack 306 win 9167 len 1188
16.350214 8883 > 52630 [.] seq 67705:68893 ack 306 win 9167 len 1188
16.350218 8883 > 52630 [.] seq 68893:70081 ack 306 win 9167 len 1188
16.350220 8883 > 52630 [.] seq 70081:71269 ack 306 win 9167 len 1188
16.350221 8883 > 52630 [.] seq 71269:72457 ack 306 win 9167 len 1188
16.350223 8883 > 52630 [.] seq 72457:73645 ack 306 win 9167 len 1188
16.350225 8883 > 52630 [.] seq 73645:74833 ack 306 win 9167 len 1188
16.451118 52630 > 8883 [.] ack 66517 win 13195 len 0
16.451136 52630 > 8883 [.] ack 66517 win 13195 len 0
16.451168 8883 > 52630 [.] seq 74833:76021 ack 306 win 9167 len 1188
16.451174 8883 > 52630 [.] seq 76021:77209 ack 306 win 9167 len 1188
16.451177 8883 > 52630 [.] seq 74833:76021 ack 306 win 9167 len 1188
16.451179 8883 > 52630 [.] seq 76021:77209 ack 306 win 9167 len 1188
16.955120 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
16.955155 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
17.760139 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
17.760165 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
19.174900 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
19.174925 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
21.792942 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
21.792961 8883 > 52630 [.] seq 66517:67705 ack 306 win 9167 len 1188
26.803909 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
26.803938 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
26.803943 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
26.803947 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
26.803952 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
26.803955 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
26.803958 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
26.803961 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
26.803964 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
26.803974 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
26.803978 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
26.803982 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
26.803985 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
26.803989 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
26.803992 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
26.803995 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
34.230610 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
34.230629 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
34.230636 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
34.230641 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
34.230646 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
34.230652 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
34.230657 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
34.230662 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
34.230667 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
34.230686 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
34.230690 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
34.230693 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
34.230697 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
34.230701 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
34.230704 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
34.230708 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
48.850193 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
48.850219 8883 > 52630 [.] seq 66517:82849 ack 306 win 9167 len 16332
48.850242 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
48.850246 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
48.850249 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
48.850252 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
48.850254 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
48.850258 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
48.850261 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
48.850273 8883 > 52630 [.] seq 82849:99181 ack 306 win 9167 len 16332
48.850276 8883 > 52630 [.] seq 99181:115513 ack 306 win 9167 len 16332
48.850279 8883 > 52630 [.] seq 115513:131845 ack 306 win 9167 len 16332
48.850282 8883 > 52630 [.] seq 131845:148177 ack 306 win 9167 len 16332
48.850285 8883 > 52630 [.] seq 148177:164509 ack 306 win 9167 len 16332
48.850287 8883 > 52630 [.] seq 164509:180841 ack 306 win 9167 len 16332
48.850290 8883 > 52630 [.] seq 180841:197173 ack 306 win 9167 len 16332
128 packets captured
362 packets received by filter
0 packets dropped by kernel
Cirno+⑨
10 years, 2 months ago