Giter Club home page Giter Club logo

snow's Issues

Reassess strategy for releasing heap allocations associated to Client/Server.

Ideally, when Client.deinit() / Server.deinit() is called, all heap allocations associated to connections pooled in either should be freed before deinit() returns.

There are two strategies on how memory/resources are cleaned up after a single connection associated with a Client / Server right now:

  1. When the socket underlying a connection is signaled to have been closed locally/by a peer, the connection would clean itself up and deallocate all of its resources.
  2. When Client.deinit() / Server.deinit() is called, all live connections are manually closed and deallocated.

There is an edge case to consider with snow's current approach: after Client.deinit() / Server.deinit() is called which cleans up connections as denoted in Strategy 2, there may still exist connections or resources associated to said Client / Server cleaning themselves up via Strategy 1 for a brief moment.

The standard practice to ensure that once Client.deinit() / Server.deinit() returns, that all heap allocations associated to a Client / Server are de-allocated, is to keep a mutex-protected cleanup queue of dead connections whose resources have yet to be destroyed. When the socket underlying a connection is signalled to have been closed locally/by a peer, the connection would queue itself into said queue.

Periodically, i.e. after a socket is accepted on a Server, or after a connection is made on a Client, the mutex-protected cleanup queue of dead connections would be polled for dead connections. If there exist entries in said queue, empty out the queue and destroy all resources associated with the entries within the queue.

The downside to this approach is that this would require maintaining a separate queue solely for resource deallocation which must be periodically checked, alongside something akin to a sync.WaitGroup which waits until all existing frames driving connections have returned.

If a more optimal approach is found, I'll take on implementing the new approach.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.