Over the past year and a half, I've been working on a layer-4 distributed post-quantum networking protocol. Thanks to rust, it is highly efficient and on-par with cloudflare's QUIC. Nearing completion now, I have finally been able to debug some of the larger parts of the program. One such part involves the session-level module.
Each session gets spawned via tokio's
spawn_local to ensure that each session is single-threaded.
SessionManager creates a
Session, and then wraps it inside an
SessionManager then places a clone inside a hashmap correlated to an IpAddr or u64 CID. The original version then gets spawned_locally as described above. As important note is that, when constructing the
Session, a cloned-version of the
SessionManager gets passed (which itself is wrapped in a
The ephemeral diffie-helman key exchange works (registration phase), and then the login stage works. After the login stage, both nodes play ping-pong with keep-alives. In RAM, the program uses about 3-5mb of RAM total. Then, mysteriously after 3 minutes or so, the client-node freezes, and the memory usage spikes to 130mb. The server node does not do this, and continues to function as expected.
A note about the purpose of having a
SessionManager inside a
Session: Sometimes, I need to remove the
Session from the hashmap inside the
SessionManager in order to process a disconnect. From a birds-eye view, this is what's happening with the references:
SessionManager spawns_locally a Session. Session has a SessionManager Rc<RefCell inside it. Sometimes, the Session calls the SessionManager to process a disconnect, of which requires exclusive &mut access through the RefCell. It seems to work, but I wanted to give you an understanding of the "topology" of the program's architecture.
Also: the SessionManager also runs on a single thread, including the Server abstraction above it. The protocol, at the layer-4 level, is all single-threaded.
Intuitively, might any of you know why my program spontaneously freezes? I know it's difficult without seeing code, but perhaps someone knows of a pitfall of setting up the program like I have.