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

chore: updates the server startup #45

Merged
merged 5 commits into from
Dec 2, 2024
Merged

chore: updates the server startup #45

merged 5 commits into from
Dec 2, 2024

Conversation

lesterli
Copy link
Contributor

@lesterli lesterli commented Dec 1, 2024

Summary

This PR updates the server startup:

  • start the http server in a goroutine, b/c httpServer.ListenAndServe() would block until shutdown
  • move the shutdown handling to RunUntilShutdown
  • replace WaitGroup to use channel

Test Plan

tested with the updated op test manager codes:

// create finality gadget
fg, err := finalitygadget.NewFinalityGadget(&fgCfg, fgDb, logger)
require.NoError(t, err)

// start finality gadget server
srv := fgsrv.NewFinalityGadgetServer(&fgCfg, fgDb, fg, shutdownInterceptor, logger)
go func() {
	err = srv.RunUntilShutdown()
	require.NoError(t, err)
}()

the logs:

INFO    server/server.go:91     gRPC server listening   {"address": "127.0.0.1:50051"}
INFO    server/server.go:120    Starting standalone HTTP server {"address": "127.0.0.1:8080"}
INFO    server/server.go:71     Finality gadget is active

server/server.go Outdated
proto.RegisterFinalityGadgetServer(grpcServer, s)

var wg sync.WaitGroup
wg.Add(1)
ready := make(chan struct{})
Copy link
Contributor

Choose a reason for hiding this comment

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

why replace WaitGroup to use channel?

also why is the channel name ready?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WaitGroup only signals goroutine started, not if server is ready to accept connections, "ready" is used b/c it is clear for the channel's purpose

Copy link
Contributor

Choose a reason for hiding this comment

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

WaitGroup only signals goroutine started, not if server is ready to accept connections

but how does it work in the past? we have always been using wg

"ready" is used b/c it is clear for the channel's purpose

ask Cursor. it's not a good name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how does it work in the past?

right, WaitGroup works in server setups, but my understanding is the key difference is channels can propagate info while WaitGroup can only signal completion

it's not a good name

yes, it is too generic, maybe listenerReady is better name

server/server.go Outdated Show resolved Hide resolved
server/server.go Show resolved Hide resolved
server/server.go Show resolved Hide resolved
@lesterli lesterli merged commit 3817ad7 into main Dec 2, 2024
11 of 12 checks passed
@lesterli lesterli deleted the fix/start-http-server branch December 2, 2024 03:16
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