Matrix-Zhang / tokio_kcp

A Kcp implementation for tokio
MIT License
176 stars 44 forks source link

KcpSession io_task_handle loop 不结束 #33

Open Jaredjin opened 1 year ago

Jaredjin commented 1 year ago

server模式下, 循环不结束,是否应该添加 input_rx.recv() 失败时结束循环?

let io_task_handle = { let session = session.clone(); tokio::spawn(async move { let mut input_buffer = [0u8; 65536];

            loop {
                tokio::select! {
                    recv_result = udp_socket.recv(&mut input_buffer), if is_client => {
                        ...
                    }

                    // bytes received from listener socket
                    input_opt = input_rx.recv() => {
                        ...
                        } else {
                            // 这里结束循环???
                            break;
                        }
                    }
                }
            }
        })
    };
zonyitoo commented 1 year ago

这里返回 None 的前提应该是 input_tx 析构,或者调用了 close(),目前的实现应该都不可能,因为 KcpSession 不会析构。

https://github.com/Matrix-Zhang/tokio_kcp/blob/89979a898c8ae2c69d83746f6af1f78a96443685/src/session.rs#L240

KcpSession 退出的条件是这里

Jhonfunk commented 11 months ago

@zonyitoo

意思是长时间运行会有大量KcpSession泄漏吗

Matrix-Zhang commented 6 months ago

@zonyitoo

意思是长时间运行会有大量KcpSession泄漏吗

如果 expire设置为了 0,长时间运行,sessions结构确实会越来越大,这是 UDP 特性导致的