Skip to content
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

Add threadpool to join the recovery threads #316

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

claddyy
Copy link
Collaborator

@claddyy claddyy commented Nov 30, 2024

Fixes #284

@Shourya742
Copy link

Any specific reason for adding another crate for thread handling?

@claddyy claddyy self-assigned this Dec 11, 2024
Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 79.16667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 78.18%. Comparing base (4747c6f) to head (014af60).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/maker/server.rs 68.18% 7 Missing ⚠️
src/maker/api.rs 86.95% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #316      +/-   ##
==========================================
- Coverage   78.26%   78.18%   -0.08%     
==========================================
  Files          32       32              
  Lines        4840     4859      +19     
==========================================
+ Hits         3788     3799      +11     
- Misses       1052     1060       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@claddyy
Copy link
Collaborator Author

claddyy commented Dec 11, 2024

Any specific reason for adding another crate for thread handling?

I tried implementing the methods from threadpool crate earlier, which was not needed. I've refined the implementation now.

Copy link

@Shourya742 Shourya742 left a comment

Choose a reason for hiding this comment

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

The approach looks fine to me. However, since you are now adding the threadPool field to the Maker struct, ensure that this field is used consistently for all instances of the thread pool within Maker. In the Maker server, there is a local thread pool—please ensure you use this thread pool there as well. Additionally, you missed joining a thread in the Maker handler. Address these issues, and this PR will be good to go.

src/maker/api.rs Show resolved Hide resolved
src/maker/api.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@KnowWhoami KnowWhoami left a comment

Choose a reason for hiding this comment

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

PartialACK.
Here are the list of review comments focusing on handling the threads and related errors in much better way.

src/maker/api.rs Outdated Show resolved Hide resolved
src/maker/api.rs Show resolved Hide resolved
src/maker/api.rs Outdated Show resolved Hide resolved
src/maker/api.rs Show resolved Hide resolved
src/maker/server.rs Show resolved Hide resolved
src/maker/server.rs Outdated Show resolved Hide resolved
src/maker/server.rs Show resolved Hide resolved
src/maker/api.rs Outdated Show resolved Hide resolved
@KnowWhoami
Copy link
Collaborator

@Shourya742

  • we can't push the tor_handle inside the maker's thread_pool because tor_handle is of type mitosis::JoinHandle while thread_pool must contain JoinHandle of type std::thread::Joinhandle.
    Though right now , this is not an issue but may become a potential bug when implementing drop trait for Maker struct.

@KnowWhoami
Copy link
Collaborator

Also there are many instances in codebase where we are not handling the thread's error correctly -> so we incorporate those enhancements in this pr itself?
For eg:

let directory_server_instance_clone = directory_server_instance.clone();
thread::spawn(move || {
start_directory_server(directory_server_instance_clone).unwrap();
});

Here unwraping the start_directory_server inside the thread doesn't make sense -> as we fail to start directory server but still we continue with further procedure like initing a maker & taker etc and that's not good.
Instead , we must propagate the error to main thread and unwrap there -> this will panic the test at that stage itself which will be good UX for tests.

@claddyy
Copy link
Collaborator Author

claddyy commented Dec 13, 2024

I appreciate the efforts put to review this PR by @KnowWhoami, but I disagree with the most of the review. I thought of addressing the review in dev-sync, so we all can come to agreement, regarding what exactly is required.

The review suggests complete structural changes without clear technical justification. Comments with suggestion to remove ThreadPool struct, removing all the Traits including Drop trait(so that it can be implemented later; but imo this doesn't make difference), manually joining threads doesn't add any improvements.

The suggested changes include harder to maintain alternatives, without any concrete benefits.

PS: I'm always open to constructive feedback and improvements.

@Shourya742
Copy link

While I appreciate the time put to review this PR by @KnowWhoami, I disagree with the most of the review. I thought of addressing the review in dev-sync, so we all can come to consensus, regarding what exactly is required.

The review suggests complete structural changes without clear technical justification. Comments with suggestion to remove ThreadPool struct, removing all the Traits including Drop trait(so that it can be implemented later; but imo this doesn't make difference), manually joining threads appears to be based on personal preferences rather than improvements.

The suggested changes include harder to maintain alternatives, without any concrete benefits.

PS: I'm always open to constructive feedback and improvements.

@claddyy just add inline to join_all and the PR is good to go.

@claddyy claddyy force-pushed the rec_threads branch 2 times, most recently from a9ea6ce to a96ac49 Compare December 16, 2024 08:02
- implement drop trait
- replace local threadpools from maker server
- restructure error handling in server
Copy link

@Shourya742 Shourya742 left a comment

Choose a reason for hiding this comment

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

ACK

Copy link

@mojoX911 mojoX911 left a comment

Choose a reason for hiding this comment

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

I like the structure. Ack.

Below is one non-blocking comment. Can be done in a followup PR too, but will be good to have to help for debugging later.

src/maker/api.rs Show resolved Hide resolved
src/maker/api.rs Show resolved Hide resolved
src/maker/api.rs Show resolved Hide resolved
@mojoX911
Copy link

Also there are many instances in codebase where we are not handling the thread's error correctly -> so we incorporate those enhancements in this pr itself? For eg:

let directory_server_instance_clone = directory_server_instance.clone();
thread::spawn(move || {
start_directory_server(directory_server_instance_clone).unwrap();
});

Here unwraping the start_directory_server inside the thread doesn't make sense -> as we fail to start directory server but still we continue with further procedure like initing a maker & taker etc and that's not good. Instead , we must propagate the error to main thread and unwrap there -> this will panic the test at that stage itself which will be good UX for tests.

Not needed for the test framework. The only other place where it makes sense is the DNS server when it creates the rpc thread. But not a major need as DNS is not user facing.

@mojoX911
Copy link

Merging this to unblock downstream works.

@mojoX911 mojoX911 merged commit b80244a into citadel-tech:master Dec 16, 2024
14 checks passed
@claddyy claddyy deleted the rec_threads branch December 16, 2024 16:22
@claddyy
Copy link
Collaborator Author

claddyy commented Dec 16, 2024

I like the structure. Ack.

Below is one non-blocking comment. Can be done in a followup PR too, but will be good to have to help for debugging later.

Addressed the review here #324.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Join the recovery threads.
4 participants