There is a probability that gen_tcp:recv will get stuck indefinitely when used

When using gen_tcp:recv and encountering an infinite blocking situation, I found that the process was constantly waiting for Ref in prim_inet:recv0(). After checking, I discovered that it was because the Ref in the process message {inet_async, S, Ref, Status} was incorrect, always being one less than the required Ref.

Thanks for raising this issue, what OTP version is this?

use OTP19.3, Is it because the version is too old that this issue occurs? The MySQL driver uses emysql, and the blocking problem happens in emysql when gen_tcp:recv gets stuck while receiving MySQL packet data.

Yes, if it is what I think it is, I fixed this in OTP-19.3.6.10 :slight_smile:

1 Like

"Thank you so much for promptly resolving this issue. I’ll upgrade the OTP version and run some tests. Our online project is a game server — could you recommend a stable OTP version? I’m really worried about running into similar issues again.

OTP-19.x support ended ~6 years ago. OTP-28.1 is the current supported version. See Erlang | endoflife.date, for a useful table.

After I upgraded to 19.3.6.13, the current issue is that when the concurrency is high, the time for individual packets to be received by the client when using gen_tcp:send to send data is longer than before. In addition, I want to know if the return of “ok” after using gen_tcp:send means that this data packet has definitely been sent out.

That’s a separate problem which may have been mitigated in a later OTP release. It makes no sense for you to stay on a decade-old release, I think you will find that many of your issues will be fixed in OTP 28.1. By staying on such an old version you’re also missing out on the JIT that was introduced in OTP 24 (and further refined from then on).

“Yes,” in the sense that the operating system has promised that it has placed the data in the send buffer. However, it’s impossible to know whether the datagrams have been sent, let alone been received on the other end.

Thank you answer. Yes, I also think we need to upgrade to the latest stable version of Erlang. However, our current online project is running on OTP 19, and the version gap is quite large. We may need to develop a comprehensive testing plan after the upgrade.