Hey all. I am writing an app that streams huge chunks of pcaps down http. I am using this function (https://gist.github.com/rrichardson/577b0e0977d05ebe22f4) in a loop.
The loop is iterating through mmap'd chunks of captured packet data, and copying them into 10k buffers which I then pass to write_to_ngx.
What happens is the outbound socket starts to fill up, so writev fails to write the complete amount:
2015/09/01 13:55:25 [debug] 31686#0: *1 writev: 1898 of 9380
2015/09/01 13:55:25 [debug] 31686#0: *1 http write filter 000000000133B6B0
2015/09/01 13:55:25 [debug] 31686#0: *1 http copy filter: -2 "/pcap/?"
2015/09/01 13:55:25 [debug] 31686#0: *1 lua reuse free buf chain, but reallocate memory because 9400 >= 24, cl:000000000133B230, p:000000000133B290
2015/09/01 13:55:25 [debug] 31686#0: *1 malloc: 000000000139C090:9400
2015/09/01 13:55:25 [debug] 31686#0: *1 lua write response
2015/09/01 13:55:25 [debug] 31686#0: *1 http output filter "/pcap/?"
2015/09/01 13:55:25 [debug] 31686#0: *1 http copy filter: "/pcap/?"
2015/09/01 13:55:25 [debug] 31686#0: *1 lua capture body filter, uri "/pcap/"
2015/09/01 13:55:25 [debug] 31686#0: *1 http postpone filter "/pcap/?" 000000000133B230
2015/09/01 13:55:25 [debug] 31686#0: *1 http chunk: 9400
2015/09/01 13:55:25 [debug] 31686#0: *1 write old buf t:1 f:0 0000000001399880, pos 0000000001399FE4, size: 7480 file: 0, size: 0
2015/09/01 13:55:25 [debug] 31686#0: *1 write old buf t:0 f:0 000000000133B6C0, pos 00000000004FAD27, size: 2 file: 0, size: 0
2015/09/01 13:55:25 [debug] 31686#0: *1 write new buf t:1 f:0 000000000133B618, pos 000000000133B618, size: 6 file: 0, size: 0
2015/09/01 13:55:25 [debug] 31686#0: *1 write new buf t:1 f:0 000000000139C090, pos 000000000139C090, size: 9400 file: 0, size: 0
2015/09/01 13:55:25 [debug] 31686#0: *1 write new buf t:0 f:0 0000000000000000, pos 00000000004FAD27, size: 2 file: 0, size: 0
After that, every time I write the buffers keep accumulating and it doesn't seem to attempt a writev again (at least not in my logs). The download just hangs.
I guess some code somewhere should do the polite thing and let the socket clear out before attempting more writes, but I'm not certain about the best way to go about this.
Is there a way to simply deschedule my lua handler and reschedule it later after the socket is cleared?
If there is no way to do that, can I just sleep when I get back a can't-write response from send_chain_link?
Thanks in advance,
Rick