node-pcap / node_pcap

libpcap bindings for node
MIT License
928 stars 253 forks source link

Loop starvation #255

Open mildsunrise opened 4 years ago

mildsunrise commented 4 years ago

If I'm not mistaken, this module could starve the loop, because it enters an infinite loop until there's no packets:

https://github.com/node-pcap/node_pcap/blob/fb9dfc9914f631dd90bc33535f4f5bdbd861cd8e/pcap_session.cc#L120-L126

So if packets arrive very fast (or the processing of each one takes a long time), this could block for an arbitrary amount of time. This would be fixed by setting a maximum of packets to read (libuv sets 32) and deferring the next read with a setTimeout if needed.

jvdassen commented 3 years ago

@mildsunrise Hello, have you been able to get around this issue? I'm running into this consistently when using a specific PCAP file and creating an offline session.

mildsunrise commented 3 years ago

I see... I only reported this issue because I knew it could theoretically happen. I'd say this isn't very hard to fix, but unfortunately I have no time to dedicate to this project right now :( Sorry