diff --git a/README.md b/README.md index d78973425..2116babde 100755 --- a/README.md +++ b/README.md @@ -336,6 +336,7 @@ Remark: ## History +* v2.0, 2015-11-16, for [#518][bug #518] fix fd leak bug when fork. 2.0.200 * v2.0, 2015-11-05, for [#511][bug #511] fix bug for restart thread. 2.0.199 * v2.0, 2015-11-02, for [#515][bug #515] use srs_freepa and SrsAutoFreeA for array. 2.0.198 * v2.0, 2015-10-28, for [ExoPlayer #828][exo #828], remove duration for live. @@ -1203,6 +1204,7 @@ Winlin [bug #512]: https://github.com/ossrs/srs/issues/512 [bug #515]: https://github.com/ossrs/srs/issues/515 [bug #511]: https://github.com/ossrs/srs/issues/511 +[bug #518]: https://github.com/ossrs/srs/issues/518 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 15c5ad911..ab0ea76ca 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -1223,10 +1223,11 @@ void SrsServer::resample_kbps() int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) { int ret = ERROR_SUCCESS; + int fd = st_netfd_fileno(client_stfd); + int max_connections = _srs_config->get_max_connections(); if ((int)conns.size() >= max_connections) { - srs_error("exceed the max connections, drop client: " "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); @@ -1234,20 +1235,26 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) return ret; } - int val; - if ((val = fcntl(fd, F_GETFD, 0)) < 0) { - ret = ERROR_SYSTEM_PID_GET_FILE_INFO; - srs_error("fnctl F_GETFD error! fd=%d. ret=%#x", fd, ret); - srs_close_stfd(client_stfd); - return ret; + + // avoid fd leak when fork. + // @see https://github.com/ossrs/srs/issues/518 + if (true) { + int val; + if ((val = fcntl(fd, F_GETFD, 0)) < 0) { + ret = ERROR_SYSTEM_PID_GET_FILE_INFO; + srs_error("fnctl F_GETFD error! fd=%d. ret=%#x", fd, ret); + srs_close_stfd(client_stfd); + return ret; + } + val |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, val) < 0) { + ret = ERROR_SYSTEM_PID_SET_FILE_INFO; + srs_error("fcntl F_SETFD error! fd=%d ret=%#x", fd, ret); + srs_close_stfd(client_stfd); + return ret; + } } - val |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, val) < 0) { - ret = ERROR_SYSTEM_PID_SET_FILE_INFO; - srs_error("fcntl F_SETFD error! fd=%d ret=%#x", fd, ret); - srs_close_stfd(client_stfd); - return ret; - } + SrsConnection* conn = NULL; if (type == SrsListenerRtmpStream) { conn = new SrsRtmpConn(this, client_stfd); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 0ff515779..c173b329c 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 199 +#define VERSION_REVISION 200 // server info. #define RTMP_SIG_SRS_KEY "SRS"