Skip to content

gloo/transport/tcp/loop: better memory management and shutdown #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

d4l3k
Copy link
Member

@d4l3k d4l3k commented Mar 28, 2025

Summary:
This overhauls how we schedule async operations on the tcp Loop.

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

  • adds a new registerDescriptor method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
  • Make Handler::handleEvents signature provide a Loop& reference so all objects don't need to hold a shared_ptr to the loop.
  • Update helpers.h to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to Loop.
  • Introduces a new shutdown() method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276

@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D72080276

d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@d4l3k d4l3k force-pushed the export-D72080276 branch from 5aa525a to c219b09 Compare March 28, 2025 22:06
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D72080276

d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:
Pull Request resolved: #422

This overhauls how we schedule async operations on the tcp Loop.

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@d4l3k d4l3k force-pushed the export-D72080276 branch from c219b09 to 309358b Compare March 28, 2025 22:09
d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@d4l3k d4l3k force-pushed the export-D72080276 branch from 309358b to 97e9072 Compare March 28, 2025 22:20
d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D72080276

d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:
Pull Request resolved: #422

This overhauls how we schedule async operations on the tcp Loop.

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@d4l3k d4l3k force-pushed the export-D72080276 branch from 97e9072 to f9c826d Compare March 28, 2025 22:23
d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@d4l3k d4l3k force-pushed the export-D72080276 branch from f9c826d to 55e29e2 Compare March 28, 2025 22:44
Summary:
Pull Request resolved: #422

This overhauls how we schedule async operations on the tcp Loop.

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
@facebook-github-bot
Copy link

This pull request was exported from Phabricator. Differential Revision: D72080276

@d4l3k d4l3k force-pushed the export-D72080276 branch from 55e29e2 to 4acb605 Compare March 28, 2025 22:47
d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
d4l3k added a commit that referenced this pull request Mar 28, 2025
Summary:

This overhauls how we schedule async operations on the tcp Loop. 

These changes greatly simplifies the memory management and simplifies the shutdown logic since memory ownership is better tied to epoll usage and relies less on shared_ptr copies everywhere to work around it.

This makes a few major changes:

* adds a new `registerDescriptor` method to Loop that provides a shared_ptr. This method will track the lifetime of the provided Handler and will release it when the epoll handle is updated/deleted.
* Make `Handler::handleEvents` signature provide a `Loop&` reference so all objects don't need to hold a shared_ptr to the loop.
* Update `helpers.h` to not manage it's own lifetime (instead using registerDescriptor shared_ptr support) and also not hold a shared_ptr to `Loop`.
* Introduces a new `shutdown()` method that allows the loop to gracefully shutdown all operations prior to destruction. This simplifies teardown on error since there a few places where handlers (Device) are managed with raw pointers. This isn't used outside of Loop currently but will be in a follow up PR.

Differential Revision: D72080276
Copy link

@fduwjj fduwjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@facebook-github-bot facebook-github-bot merged commit e348db9 into main Mar 31, 2025
7 of 9 checks passed
@d4l3k d4l3k deleted the export-D72080276 branch March 31, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants