Skip to content

Commit 160aa33

Browse files
committed
Fix shutdown and logging
1 parent 8c42046 commit 160aa33

File tree

4 files changed

+15
-39
lines changed

4 files changed

+15
-39
lines changed

server/cmd/arkd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func mainAction(_ *cli.Context) error {
7676

7777
log.Infof("Ark Server config: %+v", cfg)
7878

79-
log.Info("starting service...")
79+
log.Debug("starting service...")
8080
if err := svc.Start(); err != nil {
8181
return err
8282
}
@@ -87,7 +87,7 @@ func mainAction(_ *cli.Context) error {
8787
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, os.Interrupt)
8888
<-sigChan
8989

90-
log.Info("shutting down service...")
90+
log.Debug("shutting down service...")
9191
log.Exit(0)
9292

9393
return nil

server/internal/core/application/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ func NewService(
198198
}
199199

200200
func (s *covenantlessService) Start() error {
201-
log.Debug("starting sweeper service")
201+
log.Debug("starting sweeper service...")
202202
if err := s.sweeper.start(); err != nil {
203203
return err
204204
}
205205

206-
log.Debug("starting app service")
206+
log.Debug("starting app service...")
207207
go s.start()
208208
return nil
209209
}

server/internal/interface/grpc/handlers/arkservice.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,17 @@ type handler struct {
3232
eventsListenerHandler *broker[*arkv1.GetEventStreamResponse]
3333
transactionsListenerHandler *broker[*arkv1.GetTransactionsStreamResponse]
3434
addressSubsHandler *broker[*arkv1.SubscribeForAddressResponse]
35-
36-
stopCh <-chan struct{}
37-
stopRoundEventsCh chan struct{}
38-
stopTransactionEventsCh chan struct{}
39-
stopAddressEventsCh chan struct{}
4035
}
4136

42-
func NewHandler(version string, service application.Service, stopCh <-chan struct{}) service {
37+
func NewHandler(version string, service application.Service) service {
4338
h := &handler{
4439
version: version,
4540
svc: service,
4641
eventsListenerHandler: newBroker[*arkv1.GetEventStreamResponse](),
4742
transactionsListenerHandler: newBroker[*arkv1.GetTransactionsStreamResponse](),
4843
addressSubsHandler: newBroker[*arkv1.SubscribeForAddressResponse](),
49-
stopCh: stopCh,
50-
stopRoundEventsCh: make(chan struct{}, 1),
51-
stopTransactionEventsCh: make(chan struct{}, 1),
52-
stopAddressEventsCh: make(chan struct{}, 1),
5344
}
5445

55-
go h.listenToStop()
5646
go h.listenToEvents()
5747
go h.listenToTxEvents()
5848

@@ -369,8 +359,6 @@ func (h *handler) GetEventStream(
369359

370360
for {
371361
select {
372-
case <-h.stopRoundEventsCh:
373-
return nil
374362
case <-stream.Context().Done():
375363
return nil
376364
case ev := <-listener.ch:
@@ -521,8 +509,8 @@ func (h *handler) GetTransactionsStream(
521509

522510
for {
523511
select {
524-
case <-h.stopTransactionEventsCh:
525-
return nil
512+
// case <-h.stopTransactionEventsCh:
513+
// return nil
526514
case <-stream.Context().Done():
527515
return nil
528516
case ev := <-listener.ch:
@@ -555,8 +543,6 @@ func (h *handler) SubscribeForAddress(
555543

556544
for {
557545
select {
558-
case <-h.stopAddressEventsCh:
559-
return nil
560546
case <-stream.Context().Done():
561547
return nil
562548
case ev := <-listener.ch:
@@ -567,14 +553,6 @@ func (h *handler) SubscribeForAddress(
567553
}
568554
}
569555

570-
func (h *handler) listenToStop() {
571-
<-h.stopCh
572-
h.stopRoundEventsCh <- struct{}{}
573-
h.stopTransactionEventsCh <- struct{}{}
574-
h.stopAddressEventsCh <- struct{}{}
575-
576-
}
577-
578556
// listenToEvents forwards events from the application layer to the set of listeners
579557
func (h *handler) listenToEvents() {
580558
channel := h.svc.GetEventsChannel(context.Background())

server/internal/interface/grpc/service.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ type service struct {
4848
grpcServer *grpc.Server
4949
macaroonSvc *macaroons.Service
5050
otelShutdown func(context.Context) error
51-
52-
stopCh chan (struct{})
5351
}
5452

5553
func NewService(
@@ -96,16 +94,16 @@ func NewService(
9694
log.Debugf("generated TLS key pair at path: %s", svcConfig.tlsDatadir())
9795
}
9896

99-
stopCh := make(chan struct{}, 1)
100-
101-
return &service{version, svcConfig, appConfig, nil, nil, macaroonSvc, nil, stopCh}, nil
97+
return &service{version, svcConfig, appConfig, nil, nil, macaroonSvc, nil}, nil
10298
}
10399

104100
func (s *service) Start() error {
105101
withoutAppSvc := false
106102
if err := s.start(withoutAppSvc); err != nil {
107103
return err
108104
}
105+
log.Infof("started listening at %s", s.config.address())
106+
109107
if s.appConfig.UnlockerService() != nil {
110108
return s.autoUnlock()
111109
}
@@ -120,6 +118,7 @@ func (s *service) Stop() {
120118
log.Errorf("failed to shutdown otel: %s", err)
121119
}
122120
}
121+
log.Info("shutdown service")
123122
}
124123

125124
func (s *service) start(withAppSvc bool) error {
@@ -147,23 +146,21 @@ func (s *service) start(withAppSvc bool) error {
147146
// nolint:all
148147
go s.server.ListenAndServeTLS("", "")
149148
}
150-
log.Infof("started listening at %s", s.config.address())
151149

152150
return nil
153151
}
154152

155153
func (s *service) stop(withAppSvc bool) {
156154
if withAppSvc {
157-
s.stopCh <- struct{}{}
158155
appSvc, _ := s.appConfig.AppService()
159156
if appSvc != nil {
160157
appSvc.Stop()
161158
log.Info("stopped app service")
162159
}
160+
s.grpcServer.Stop()
163161
}
164-
//nolint:all
162+
// nolint
165163
s.server.Shutdown(context.Background())
166-
log.Info("stopped grpc server")
167164
}
168165

169166
func (s *service) newServer(tlsConfig *tls.Config, withAppSvc bool) error {
@@ -201,7 +198,7 @@ func (s *service) newServer(tlsConfig *tls.Config, withAppSvc bool) error {
201198
return err
202199
}
203200
appSvc = svc
204-
appHandler := handlers.NewHandler(s.version, appSvc, s.stopCh)
201+
appHandler := handlers.NewHandler(s.version, appSvc)
205202
indexerSvc, err := s.appConfig.IndexerService()
206203
if err != nil {
207204
return err
@@ -309,6 +306,7 @@ func (s *service) newServer(tlsConfig *tls.Config, withAppSvc bool) error {
309306
httpServerHandler = h2c.NewHandler(httpServerHandler, &http2.Server{})
310307
}
311308

309+
s.grpcServer = grpcServer
312310
s.server = &http.Server{
313311
Addr: s.config.address(),
314312
Handler: httpServerHandler,

0 commit comments

Comments
 (0)