正在显示
3 个修改的文件
包含
23 行增加
和
3 行删除
| @@ -1286,6 +1286,7 @@ Winlin | @@ -1286,6 +1286,7 @@ Winlin | ||
| 1286 | [bug #512]: https://github.com/ossrs/srs/issues/512 | 1286 | [bug #512]: https://github.com/ossrs/srs/issues/512 |
| 1287 | [bug #515]: https://github.com/ossrs/srs/issues/515 | 1287 | [bug #515]: https://github.com/ossrs/srs/issues/515 |
| 1288 | [bug #511]: https://github.com/ossrs/srs/issues/511 | 1288 | [bug #511]: https://github.com/ossrs/srs/issues/511 |
| 1289 | +[bug #518]: https://github.com/ossrs/srs/issues/518 | ||
| 1289 | [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx | 1290 | [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx |
| 1290 | 1291 | ||
| 1291 | [exo #828]: https://github.com/google/ExoPlayer/pull/828 | 1292 | [exo #828]: https://github.com/google/ExoPlayer/pull/828 |
| @@ -8,7 +8,7 @@ RED="\\033[31m" | @@ -8,7 +8,7 @@ RED="\\033[31m" | ||
| 8 | GREEN="\\033[32m" | 8 | GREEN="\\033[32m" |
| 9 | YELLOW="\\033[33m" | 9 | YELLOW="\\033[33m" |
| 10 | BLACK="\\033[0m" | 10 | BLACK="\\033[0m" |
| 11 | -POS="\\033[103G" | 11 | +POS="\\033[94G" |
| 12 | 12 | ||
| 13 | # if need to log to file, change the log path. | 13 | # if need to log to file, change the log path. |
| 14 | if [[ ! $log ]]; then | 14 | if [[ ! $log ]]; then |
| @@ -1253,10 +1253,10 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | @@ -1253,10 +1253,10 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | ||
| 1253 | { | 1253 | { |
| 1254 | int ret = ERROR_SUCCESS; | 1254 | int ret = ERROR_SUCCESS; |
| 1255 | 1255 | ||
| 1256 | + int fd = st_netfd_fileno(client_stfd); | ||
| 1257 | + | ||
| 1256 | int max_connections = _srs_config->get_max_connections(); | 1258 | int max_connections = _srs_config->get_max_connections(); |
| 1257 | if ((int)conns.size() >= max_connections) { | 1259 | if ((int)conns.size() >= max_connections) { |
| 1258 | - int fd = st_netfd_fileno(client_stfd); | ||
| 1259 | - | ||
| 1260 | srs_error("exceed the max connections, drop client: " | 1260 | srs_error("exceed the max connections, drop client: " |
| 1261 | "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); | 1261 | "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); |
| 1262 | 1262 | ||
| @@ -1265,6 +1265,25 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | @@ -1265,6 +1265,25 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | ||
| 1265 | return ret; | 1265 | return ret; |
| 1266 | } | 1266 | } |
| 1267 | 1267 | ||
| 1268 | + // avoid fd leak when fork. | ||
| 1269 | + // @see https://github.com/ossrs/srs/issues/518 | ||
| 1270 | + if (true) { | ||
| 1271 | + int val; | ||
| 1272 | + if ((val = fcntl(fd, F_GETFD, 0)) < 0) { | ||
| 1273 | + ret = ERROR_SYSTEM_PID_GET_FILE_INFO; | ||
| 1274 | + srs_error("fnctl F_GETFD error! fd=%d. ret=%#x", fd, ret); | ||
| 1275 | + srs_close_stfd(client_stfd); | ||
| 1276 | + return ret; | ||
| 1277 | + } | ||
| 1278 | + val |= FD_CLOEXEC; | ||
| 1279 | + if (fcntl(fd, F_SETFD, val) < 0) { | ||
| 1280 | + ret = ERROR_SYSTEM_PID_SET_FILE_INFO; | ||
| 1281 | + srs_error("fcntl F_SETFD error! fd=%d ret=%#x", fd, ret); | ||
| 1282 | + srs_close_stfd(client_stfd); | ||
| 1283 | + return ret; | ||
| 1284 | + } | ||
| 1285 | + } | ||
| 1286 | + | ||
| 1268 | SrsConnection* conn = NULL; | 1287 | SrsConnection* conn = NULL; |
| 1269 | if (type == SrsListenerRtmpStream) { | 1288 | if (type == SrsListenerRtmpStream) { |
| 1270 | conn = new SrsRtmpConn(this, kafka, client_stfd); | 1289 | conn = new SrsRtmpConn(this, kafka, client_stfd); |
-
请 注册 或 登录 后发表评论