1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #518, fix fd leak bug when fork. 2.0.200

This commit is contained in:
winlin 2015-11-16 18:06:44 +08:00
parent 803c899a9b
commit 2310b2da59
3 changed files with 24 additions and 15 deletions

View file

@ -336,6 +336,7 @@ Remark:
## History ## 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-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-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. * 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 #512]: https://github.com/ossrs/srs/issues/512
[bug #515]: https://github.com/ossrs/srs/issues/515 [bug #515]: https://github.com/ossrs/srs/issues/515
[bug #511]: https://github.com/ossrs/srs/issues/511 [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 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
[exo #828]: https://github.com/google/ExoPlayer/pull/828 [exo #828]: https://github.com/google/ExoPlayer/pull/828

View file

@ -1223,10 +1223,11 @@ void SrsServer::resample_kbps()
int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
int fd = st_netfd_fileno(client_stfd); int fd = st_netfd_fileno(client_stfd);
int max_connections = _srs_config->get_max_connections(); int max_connections = _srs_config->get_max_connections();
if ((int)conns.size() >= max_connections) { if ((int)conns.size() >= max_connections) {
srs_error("exceed the max connections, drop client: " srs_error("exceed the max connections, drop client: "
"clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd);
@ -1234,6 +1235,10 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
return ret; return ret;
} }
// avoid fd leak when fork.
// @see https://github.com/ossrs/srs/issues/518
if (true) {
int val; int val;
if ((val = fcntl(fd, F_GETFD, 0)) < 0) { if ((val = fcntl(fd, F_GETFD, 0)) < 0) {
ret = ERROR_SYSTEM_PID_GET_FILE_INFO; ret = ERROR_SYSTEM_PID_GET_FILE_INFO;
@ -1248,6 +1253,8 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
srs_close_stfd(client_stfd); srs_close_stfd(client_stfd);
return ret; return ret;
} }
}
SrsConnection* conn = NULL; SrsConnection* conn = NULL;
if (type == SrsListenerRtmpStream) { if (type == SrsListenerRtmpStream) {
conn = new SrsRtmpConn(this, client_stfd); conn = new SrsRtmpConn(this, client_stfd);

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR 2 #define VERSION_MAJOR 2
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 199 #define VERSION_REVISION 200
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"