Skip to content

Commit

Permalink
add relay statemachine to prevent multiple chan close (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 authored Aug 21, 2024
1 parent cd3dcc5 commit a2f5c39
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pkg/solana/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TxManager interface {
var _ relaytypes.Relayer = &Relayer{} //nolint:staticcheck

type Relayer struct {
services.StateMachine
lggr logger.Logger
chain Chain
stopCh services.StopChan
Expand All @@ -49,17 +50,21 @@ func (r *Relayer) Name() string {

// Start starts the relayer respecting the given context.
func (r *Relayer) Start(context.Context) error {
// No subservices started on relay start, but when the first job is started
if r.chain == nil {
return errors.New("Solana unavailable")
}
return nil
return r.StartOnce("SolanaRelayer", func() error {
// No subservices started on relay start, but when the first job is started
if r.chain == nil {
return errors.New("Solana unavailable")
}
return nil
})
}

// Close will close all open subservices
func (r *Relayer) Close() error {
close(r.stopCh)
return nil
return r.StopOnce("SolanaRelayer", func() error {
close(r.stopCh)
return nil
})
}

func (r *Relayer) Ready() error {
Expand Down

0 comments on commit a2f5c39

Please sign in to comment.