<p>I'm working on a project that requires me to run two concurrent goroutines that listen on two different network interfaces and capture all traffic that passes through them. However, I've noticed that after about 200 successful packet captures, my program stops capturing with no errors to be seen.</p>
<p>My initial thought is that a deadlock is being created somewhere within the included gopacket/pcap libraries. Any thoughts/suggestions on this are greatly appreciated. </p>
<p>Thanks.</p>
<hr/>**评论:**<br/><br/>bradleyfalzon: <pre><p>Without seeing the source code, I can't help too much but provide you with an example on how I'm doing something:</p>
<p><a href="https://gist.github.com/bradleyfalzon/1d05d490e4f8b1708d866e3660ed7b11" rel="nofollow">https://gist.github.com/bradleyfalzon/1d05d490e4f8b1708d866e3660ed7b11</a></p>
<p>This is some old code so I've changed my style slightly, but when the application starts, it starts a single listener and processes each specific packet in another go routine.</p>
<p>It's not quite similar, nor do I think it'll help too much.</p>
<p>But I think what you really need to do is start paring the issue back and making it simpler, does the issue happen in one thread? etc etc</p></pre>ymmit987: <pre><p>I'm not sure why this was the solution, but after I kicked off my two main goroutines in my main() func, I started an infinite for{} loop to keep the program from closing. Instead I changed it to a select{} on a whim and it solved my problem of the program hanging after a seemingly random amount of time. </p></pre>bradleyfalzon: <pre><p>Interest to know and yeah, select{} sleeps whereas for{} spins.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传