-
Notifications
You must be signed in to change notification settings - Fork 137
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
Graceful shutdown for mining-proxy #1021
Conversation
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
🚨 2 ALERTS: Threshold Boundary Limits exceeded!
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
Bencher
🚨 8 ALERTS: Threshold Boundary Limits exceeded!
Click to view all benchmark results
Bencher - Continuous Benchmarking View Public Perf Page Docs | Repo | Chat | Help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this, added few small comments
80f0106
to
329bfc3
Compare
@johnnyasantoss can you write some instructions on how to reproduce the original issue? I still haven't been able to reproduce it |
Try Ideally it should be |
Should I keep rebasing or only rebase once there are enough reviews? |
this is tricky, we discussed it a bit on the last minutes of our call yesterday basically, every PR that gets merged before this would mean you need to rebase it, which is very boring and doesn't really scale well we established the following convention:
|
Should we add this to contributing.md ? |
I would also add about the commit strategy. Should we use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have been looking into the code a bit and it would be good to do a couple of things here:
It would be very nice if you could add unit test to test function start_mining_proxy
, that I think can look something like this:
async fn start_mining_proxy(config: Config) {
let group_id = Arc::new(Mutex::new(GroupId::new()));
lib::ROUTING_LOGIC
.set(Mutex::new(
lib::initialize_r_logic(&config.upstreams, group_id, config.clone()).await,
))
.expect("BUG: Failed to set ROUTING_LOGIC");
info!("PROXY INITIALIZING");
lib::initialize_upstreams(config.min_supported_version, config.max_supported_version).await;
// Wait for downstream connection
let socket = SocketAddr::new(
config.listen_address.parse().unwrap(),
config.listen_mining_port,
);
let (shutdown_tx, mut shutdown_rx) = oneshot::channel();
let listener = TcpListener::bind(socket).await.unwrap();
info!("Listening on {}", socket.to_string());
tokio::select! {
_ = lib::downstream_mining::listen_for_downstream_mining(listener) => {
warn!("Downstream mining listener exited prematurely");
},
_ = &mut shutdown_rx => {
info!("Closing listener on {}", socket.to_string());
let _ = shutdown_tx.send(());
}
_ = tokio::signal::ctrl_c() => {
let _ = shutdown_tx.send(());
info!("Interrupt received");
}
}
info!("Shutdown done");
}
Notice how I changed the tokio::select
but I dont have strong opinion about it, but I do think we should try to avoid nested select's
.
This would also require to change listen_for_downstream_mining
signature to accept TcpListener
rather than SocketAddr
.
This way we separate the binary stuff(getting the config), and the actual service initiating function and we can test it more easily to verify your solution.
If you think this is too much, I am happy to pick it up in a later PR.
Here is a commit with a bit of changes jbesraa@8753830
@marathon-gary started working on #1030 so we should move this discussion to that PR |
8aa6914
to
a4b4640
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! this looks much better. Ill create a followup pr to cover another couple of things in mining-proxy
(like remove the dead_code
, adding tests..)
could you please tide up the commit message?
@jbesraa tide up? Is there a pattern that we must follow? Something like conventional commits? Asking because I didn't see any docs about this and this is my first PR here. I still need to reformat and add the tests you mentioned. I was fighting tooling yesterday. Apparently, Rust has gotten a lot of tooling nowadays, so I need to configure properly my dev env. |
Commit guidelines: https://cbea.ms/git-commit/ sounds good, feel free to bing me once its ready for review |
@johnnyasantoss could you please cherry-pick this commit jbesraa@f91be81 here? |
@jbesraa the permission to write is enabled (you mentioned on the dev call) |
a717051
to
5816894
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can merge this. Ill do a bit of testing with mining-proxy
as part of #1066
@johnnyasantoss This needs a rebase |
165d0dd
to
690b109
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnnyasantoss Can you please organize your commits so they are grouped correctly? for example the spawn
thing shouldn't be in its own commit, same for the typos.
The first commits has refactor + small fixes + the actual solution, so I would organize that as well. In this PR you can end-up with the following commits:
1 - all the typos/format/ordering imports(you can also break this into multiple commits if one of the changes is too big)
2 - code refactor(same, you can decide to break this)
3 - actual code for graceful shutdown
Could you also remove 2e48ac1 as we currently don't commit lock files
Please refer to this https://cbea.ms/git-commit/ for a better understanding to what we are trying to achieve in the commit history.
Changes: - Add listener on exit signals - Add channel to unbind listener as well - Organize main fn to handle signals and ownership of sockets - Fix typos in docs - Format imports - Remove unused spawn - Simplifies the code a bit reducing nesting and matches with unused arms
(cherry picked from commit f91be81) Co-authored-by: jbesraa <[email protected]>
690b109
to
5b5d28e
Compare
Add graceful shutdown for mining proxy fixing #484
PS: I'm not sure if I should merge against dev or main