ps_recv shows packets that aren't being sent to PacketReady
I am trying to troubleshoot an issue where I have problems with https sessions showing up in the ps_recv but PcapSession::PacketReady() is not getting called for these packets (I used a print statement to check). It starts working after the first http transaction.
Update: An empty read is occurring when the packets should be received.
I was able to get it to work but I did somewhat of a hack job I made this change to pcap.js starting from line 61:
me.readWatcher.callback = function pcap_read_callback() {
var packets_read = me.session.dispatch(me.buf);
if (packets_read < 1) {
// TODO - figure out what is causing this, and if it is bad.
me.empty_reads += 1;
setTimeout(function(){
console.log("delayed read",me.session.dispatch(me.buf));
},500);
}
};
In pcap_session.cc I added
int packet_count=0;
int packet_ret;
do {
packet_count+= packet_ret = pcap_dispatch(session->pcap_handle, 1, PacketReady, (u_char *)session);
} while (packet_ret > 0);
std::cout <<"Dispatch: " <<packet_count <<std::endl;
return scope.Close(Integer::NewFromUnsigned(packet_count));
What is bad about this fix is that it calls dispatch twice. The problem is that the readwatcher calls dispatch before the kernel is ready to hand over the packets. If the packets sit around too long, they get cleared from the queue leading to a discrepancy between ps_recv and the number of dispatched packets.
I don't know that there is really a good fix for this. One option might be to spawn a thread for handling pcap_dispatch and feed the results back to the node_js thread.