Skip to content
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

Replace using of select() with poll() #6264

Closed
AGulev opened this issue Dec 15, 2021 · 1 comment · Fixed by #6296
Closed

Replace using of select() with poll() #6264

AGulev opened this issue Dec 15, 2021 · 1 comment · Fixed by #6296
Labels
network Issue related to network connectivity task A task that needs to be performed
Projects

Comments

@AGulev
Copy link
Contributor

AGulev commented Dec 15, 2021

Task (REQUIRED):
image

Sometimes SDKs use more than 1024 FD, if the engine a game use API that uses select() under the hood at the same time, than the game crashes.

The engine uses select() in 6 files:
qsa.c - openAl/Alc
wsocket.c - luasocket
usocket.c - luasocket
net_sockets.c - mdedtls
sslsocket.c - dlib
socket.cpp - dlib

select() (doc) should be replaced with poll() (doc) to avoid this crash.

Expected outcome (REQUIRED):

No more crashes in such cases.
A couple of examples:

...
#00  pc 0000000000000668  [vdso] (__kernel_rt_sigreturn)
  #00  pc 000000000004e408  /apex/com.android.runtime/lib64/bionic/libc.so (abort+160)
  #00  pc 0000000000076c00  /apex/com.android.runtime/lib64/bionic/libc.so (__fortify_fatal(char const*, ...)+124)
  #00  pc 0000000000076b1c  /apex/com.android.runtime/lib64/bionic/libc.so (__FD_SET_chk+120)
  #00  pc 00000000001f4d08 (dmConnectionPool::ConnectSocket(dmConnectionPool::ConnectionPool*, dmSocket::Address, unsigned short, int, dmConnectionPool::Connection*, dmSocket::Result*)) (SourceCode: /home/runner/work/defold/defold/engine/dlib/build/../src/dlib/connection_pool.cpp:273)
...

One more crash:
https://github.com/defold/extension-poco/blob/master/poco/lua/defold-poco.lua#L146

@AGulev AGulev added the task A task that needs to be performed label Dec 15, 2021
@britzl britzl added this to To do in 1.2.192 via automation Dec 15, 2021
@britzl britzl added the network Issue related to network connectivity label Dec 15, 2021
@britzl
Copy link
Contributor

britzl commented Dec 30, 2021

wsocket.c - luasocket
usocket.c - luasocket

select() is used from the Lua function socket_select(). The best way forward would be to add support for a socket_poll() function.

https://github.com/diegonehab/luasocket

socket.cpp - dlib

Done!

sslsocket.cpp - dlib

Used by RecvTimeout() as a replacement for the default mbedtls_net_recv_timeout. I've tried switching from select to poll here but I'm getting SSL handshake timeouts when using equivalent code using poll instead of select.

net_sockets.c - mdedtls

We do not use any affected code from this file.

qsa.c - openAl/Alc

Not used. This backend has been removed in more recent versions of OpenAL: https://github.com/kcat/openal-soft/blob/master/ChangeLog#L157

@britzl britzl moved this from To do to In progress in 1.2.192 Jan 2, 2022
1.2.192 automation moved this from In progress to Done Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network Issue related to network connectivity task A task that needs to be performed
Projects
No open projects
1.2.192
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants