Fw: [问题] 如何定位NDK Block issue

楼主: windows2k (程式宅 <囧>)   2018-10-20 12:06:59
※ [本文转录自 AndroidDev 看板 #1Rog49g9 ]
作者: windows2k (程式宅 <囧>) 看板: AndroidDev
标题: [问题] 如何定位NDK Block issue
时间: Sat Oct 20 11:29:10 2018
这问题有点难描述...不是Crash, 所以不能用ndk-stack下去看
而是Native code的程式码被Blocked住了
同样的程式码, 在Android 6之前都运行正常, 在Android 7之后就出现了
由于是Linux based, Linux 我试不出来此Bug
程式码逻辑大概是这样
开一个 listen socket -> 设成 NonBlocking Mode
epoll -> 得到一个 Read Event -> Accept new socket
程式码来自于知名Network Library, 我想错误的机率不大
经过夹击之后, 我发现问题可能出在 Accept new socket这部分
Accept前后程式码没有System call, 并且没有Blocking的可能
根据 Linux Manual 上所写
If no pending connections are present on the queue, and the socket is not
marked as nonblocking, accept() blocks the caller until a connection is
present. If the socket is marked nonblocking and no pending connections are
present on the queue, accept() fails with the error EAGAIN or EWOULDBLOCK.
理论上根本不会有问题...
于是作了以下尝试
1. 在Accept之前再次将 Socket 设成 non-blocking => 没用
2. 在Accept前后加上 __android_log_print 做夹击 => 做不出来, 但不是我想要的解法
我的问题主要有两个
1. 如何证明 accept 会卡住
2. 如何避开这个问题
卡关了很久, 希望有人给我一点想法吧, 谢谢
作者: yvb   2018-10-20 22:02:00
是否有可以 reproduce 的 sample code ?以及是否使用 strace 追踪 syscall 的情况了呢?

Links booklink

Contact Us: admin [ a t ] ucptt.com