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

feat(jstzd): use AsyncDropper in JstzdServer #656

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

huancheng-trili
Copy link
Collaborator

@huancheng-trili huancheng-trili commented Nov 13, 2024

Context

Closes JSTZ-121.

JSTZ-121

Description

Wrap the test in a future so that we can still call stop at the end of the test to clean up everything before the program exits should the test fail and panic. Otherwise, the test program does not actually close after the panic and the baker and octez-node processes remain running even after the test program terminates.

In a tokio task, panic is captured and returned as Err, so handling failed assertions like this is much simpler than trying to do something like catch_unwind.

Manually testing the PR

The test should still work as is.

@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch from 030aacd to 7b9dea8 Compare November 13, 2024 15:52
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 76.47059% with 8 lines in your changes missing coverage. Please review.

Project coverage is 45.85%. Comparing base (dc006a6) to head (416eae3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/jstzd/src/task/jstzd.rs 76.47% 2 Missing and 6 partials ⚠️
Files with missing lines Coverage Δ
crates/jstzd/src/task/jstzd.rs 77.29% <76.47%> (+3.58%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc006a6...416eae3. Read the comment docs.


🚨 Try these New Features:

@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 8ccbd02 to 85eebb4 Compare November 13, 2024 15:53
@huancheng-trili huancheng-trili marked this pull request as ready for review November 13, 2024 16:14
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch 2 times, most recently from 407a72e to 616a392 Compare November 15, 2024 15:46
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 85eebb4 to 7f885a2 Compare November 15, 2024 15:50
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch from 616a392 to fec3507 Compare November 15, 2024 15:58
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 7f885a2 to 2cc9340 Compare November 15, 2024 16:00
@huancheng-trili huancheng-trili assigned zcabter and unassigned ryutamago Nov 18, 2024
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch 2 times, most recently from a805821 to 75e620b Compare November 18, 2024 14:40
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 2cc9340 to f890e1c Compare November 18, 2024 15:14
Copy link
Collaborator

@zcabter zcabter left a comment

Choose a reason for hiding this comment

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

Isn't the problem because JstzServer, although it implements AsyncDrop, isn't instantiated with AsyncDropper<JstzServer>?
Since AsyncDropper requires impl Default, ServerState.jstzd_config field might have to wrapped in Option<> which is rather inconvenient :(

If there is a jstzd panics for some reason, we definitely want the octez resources to be cleaned up. Is there a better way to to hook self.stop()when the server starts up?

@zcabter zcabter assigned huancheng-trili and unassigned zcabter Nov 18, 2024
@zcabter zcabter self-requested a review November 18, 2024 19:42
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from f890e1c to 281235b Compare November 19, 2024 11:08
@huancheng-trili
Copy link
Collaborator Author

Isn't the problem because JstzServer, although it implements AsyncDrop, isn't instantiated with AsyncDropper?

Yes. I thought implementing AsyncDrop would be sufficient and forgot about AsyncDropper. I've changed this PR and added AsyncDropper to JstzServer. The implementation might look a bit awkward because of the locks. Ideally AsyncDrop should be implemented for ServerState, but there will be some borrow_mut issues without having the lock. The only way to get the lock involved is to wrap everything with a struct and implement AsyncDrop for that struct instead. Now AsyncDropper is embedded in JstzServer. At least with this we don't need to write AsyncDropper<JstzServer> everywhere.

Since AsyncDropper requires impl Default, ServerState.jstzd_config field might have to wrapped in Option<> which is rather inconvenient :(

That's true, but it's not that inconvenient since the server does not really access jstzd_config that much. I think it's okay to just wrap it.

If there is a jstzd panics for some reason, we definitely want the octez resources to be cleaned up. Is there a better way to to hook self.stop()when the server starts up?

AsyncDrop should be able to handle what we can handle for now. Based on my observation, AsyncDrop for JstzdServer does clean up octez resources in the following cases:

  • when something in the program outside of JstzdServer panics and causes the program to terminate
  • when something inside JstzdServer itself, e.g. some route handler, panics
  • when something inside Jstzd itself, e.g. something bad in any of its methods, panics

At this moment, there aren't really that many places in Jstzd where it can panic. It has only a few methods and AsyncDrop for JstzdServer can handle failures at those places. For spawn, after calling spawn, the child processes continue on their owns and Jstzd does not get affected should those processes fail somehow. I think there was some discussion before regarding making jstzd "recover" from subprocess failures and we can look into this later on, but for now Jstzd won't be aware of those events.

Copy link
Collaborator

@zcabter zcabter left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@zcabter zcabter assigned huancheng-trili and unassigned zcabter Nov 19, 2024
@huancheng-trili huancheng-trili changed the title test(jstzd): clean up after failed jstzd test feat(jstzd): use AsyncDropper in JstzdServer Nov 19, 2024
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch from 75e620b to 3eaef9d Compare November 19, 2024 13:26
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 281235b to bf6b52b Compare November 19, 2024 13:27
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch 2 times, most recently from 7674e6e to 4690225 Compare November 20, 2024 09:51
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from bf6b52b to 94f7586 Compare November 20, 2024 09:55
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-5 branch 2 times, most recently from 494360e to 29efe77 Compare November 21, 2024 13:14
Base automatically changed from huanchengchang-jstz-121-5 to main November 21, 2024 13:23
@huancheng-trili huancheng-trili force-pushed the huanchengchang-jstz-121-6 branch from 94f7586 to 416eae3 Compare November 21, 2024 13:24
@huancheng-trili huancheng-trili merged commit 5fbe97d into main Nov 21, 2024
5 checks passed
@huancheng-trili huancheng-trili deleted the huanchengchang-jstz-121-6 branch November 21, 2024 13:50
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.

3 participants