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

[Bug]: server/v2 Stop() is not called for all components before process shutdown #22405

Closed
1 task done
kocubinski opened this issue Oct 31, 2024 · 1 comment · Fixed by #22455
Closed
1 task done
Assignees
Labels

Comments

@kocubinski
Copy link
Member

kocubinski commented Oct 31, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Currently (another bug) Close() is not being called on the RootStore on application exit. I added this patch to server/v2/store to address that:

diff --git a/server/v2/store/server.go b/server/v2/store/server.go
index 897773abf2..23e2c1ef47 100644
--- a/server/v2/store/server.go
+++ b/server/v2/store/server.go
@@ -2,6 +2,7 @@ package store

 import (
        "context"
+       "errors"
        "fmt"

        "github.com/spf13/cobra"
@@ -47,7 +48,12 @@ func (s *Server[T]) Start(context.Context) error {
 }

 func (s *Server[T]) Stop(context.Context) error {
-       return nil
+       errs := errors.Join(
+               s.backend.GetStateCommitment().Close(),
+               s.backend.GetStateStorage().Close(),
+       )
+       fmt.Println("store server stopped")
+       return errs
 }

but it doesn't seem to run, the Println never reached. It looks like since we're waiting for a SIGINT in a background goroutine, and then calling stop from that same thread (see below) that the control thread is exiting before that thread can complete it's work. Control thread should block (not exit) while Stop completes.

if err := server.Stop(ctx); err != nil {

Cosmos SDK Version

main

How to reproduce?

❯ COSMOS_BUILD_OPTIONS=v2 make install && make init-simapp-v2 && simdv2 start

Then send a SIGINT (^C from terminal) to the process.

@julienrbrt
Copy link
Member

julienrbrt commented Nov 4, 2024

I'd be happy to cherry-pick some of your changes from #22406 and try my deferring suggestion (#22406 (comment)) if you aren't on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: 🥳 Done
Development

Successfully merging a pull request may close this issue.

2 participants