New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当socket发生错误时,关闭了socket,却没有回调onclose方法 #1373
Comments
出错和正常关闭是两个事件。你需要在出错时主动调用 socket.close ,这样才会收到 close 事件。 |
我明白了。因为历史遗留,有些出错处理在 c 层调用了 force_close 导致后续主动 close 未能触发关闭事件。这里我明天改一下。 另外,问一下这里的 socket 出错指的的什么错误?出错信息是什么? |
是在forward_message_tcp里。错误信息是: socket: error on 99 Connection reset by peer |
此处不应该 最后一次提交修正了这个问题,删除了 目前在 https://github.com/cloudwu/skynet/blob/master/lualib/skynet/socket.lua#L159 主动 shutdown 了 fd ,这会导致不再能读。这点以后会考虑去掉。之所以在遇到 error 就主动关闭,是考虑到兼容 skynet 旧版本的行为(遇到错误自动关闭),避免泄露 fd 。 |
用的最新的代码。在forward_message_tcp里,错误信息是: socket: error on 99 Connection reset by peer。还是出现。出现的机率没有以前大,还是没有调用onclose。 |
你在对方关闭“读”后继续写一定会产生 “Connection reset by peer” ,这是正常的。 出错后没有产生
注: 之前之所以没有产生 你看看在 https://github.com/cloudwu/skynet/blob/master/skynet-src/socket_server.c#L1134
其一,就是之前修正的地方,如果调用了 force_close 那么 socket_invalid 会返回真,导致这里不产生 SOCKET_CLOSE 。 |
我尝试写个测试来触发 onclose 没调用的情况,没能成功。 不过发现了一处 poll 循环中处理 eof 事件的小 bug (最近的提交中修正),我认为修复的问题和这里漏掉 onclose 无关。 |
发生上面情况的原因大概如下: 然后,由于在应用层主动调用了socket.close,来关闭上面的socket fd(并不知道是发生了错误,只是由于有两个socket fd是关联的,当另一个fd不可用时,应该层主动关闭的。因此会出现随机出现的现象)。 而在socket.close调用中,会把socket_pool[id] = nil 设置成nil。 然后在SKYNET_SOCKET_TYPE_CLOSE的处理中,由于s为nil,不会再走到on_close那里。 |
我今天把 onclose 的 callback 放在外面,应该能解决这个倒序的问题。 |
No description provided.
The text was updated successfully, but these errors were encountered: