Skip to content

Commit

Permalink
fix: Receiver can cause panic during reload in Log Carver
Browse files Browse the repository at this point in the history
Fixes #400
  • Loading branch information
driskell committed Apr 1, 2023
1 parent cdeeb73 commit c43f935
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lc-lib/transports/tcp/courier/receiverfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func NewReceiverFactory(p *config.Parser, configPath string, unUsed map[string]i

// NewReceiver returns a new Receiver interface using the settings from the ReceiverFactory
func (f *ReceiverFactory) NewReceiver(ctx context.Context, listen string, eventChan chan<- transports.Event) transports.Receiver {
return f.ReceiverFactory.NewReceiverWithProtocol(ctx, listen, eventChan, &protocolFactory{isClient: false})
return f.ReceiverFactory.NewReceiverWithProtocol(ctx, f, listen, eventChan, &protocolFactory{isClient: false})
}

func (f *ReceiverFactory) ShouldRestart(newFactory transports.ReceiverFactory) bool {
return f.ReceiverFactory.ShouldRestart(newFactory.(*ReceiverFactory).ReceiverFactory)
}

// Register the transports
Expand Down
8 changes: 4 additions & 4 deletions lc-lib/transports/tcp/receiverfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ func (f *ReceiverFactory) NewReceiver(context.Context, string, chan<- transports
}

// NewReceiverWithProtocol creates a new receiver with the given protocol
func (f *ReceiverFactory) NewReceiverWithProtocol(ctx context.Context, bind string, eventChan chan<- transports.Event, protocolFactory ProtocolFactory) transports.Receiver {
func (f *ReceiverFactory) NewReceiverWithProtocol(ctx context.Context, factory transports.ReceiverFactory, bind string, eventChan chan<- transports.Event, protocolFactory ProtocolFactory) transports.Receiver {
backoffName := fmt.Sprintf("[R %s] Receiver Reset", bind)
ret := &receiverTCP{
config: f,
factory: factory,
bind: bind,
eventChan: eventChan,
connections: make(map[*connection]*connection),
Expand All @@ -80,7 +81,6 @@ func (f *ReceiverFactory) Validate(p *config.Parser, configPath string) (err err
return f.ServerTlsConfiguration.TlsValidate(f.EnableTls, p, configPath)
}

func (f *ReceiverFactory) ShouldRestart(newFactory transports.ReceiverFactory) bool {
newFactoryImpl := newFactory.(*ReceiverFactory)
return f.ServerTlsConfiguration.HasChanged(newFactoryImpl.ServerTlsConfiguration)
func (f *ReceiverFactory) ShouldRestart(newFactory *ReceiverFactory) bool {
return f.ServerTlsConfiguration.HasChanged(newFactory.ServerTlsConfiguration)
}
3 changes: 2 additions & 1 deletion lc-lib/transports/tcp/receivertcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type receiverTCP struct {
ctx context.Context
shutdownFunc context.CancelFunc
config *ReceiverFactory
factory transports.ReceiverFactory
bind string
eventChan chan<- transports.Event
connections map[*connection]*connection
Expand All @@ -49,7 +50,7 @@ type receiverTCP struct {

// Factory returns the associated factory
func (t *receiverTCP) Factory() transports.ReceiverFactory {
return t.config
return t.factory
}

// startController starts the controller
Expand Down
6 changes: 5 additions & 1 deletion lc-lib/transports/tcp/stream/receiverfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func NewReceiverFactory(p *config.Parser, configPath string, unUsed map[string]i

// NewReceiver returns a new Receiver interface using the settings from the ReceiverFactory
func (f *ReceiverFactory) NewReceiver(ctx context.Context, bind string, eventChan chan<- transports.Event) transports.Receiver {
return f.ReceiverFactory.NewReceiverWithProtocol(ctx, bind, eventChan, &protocolFactory{})
return f.ReceiverFactory.NewReceiverWithProtocol(ctx, f, bind, eventChan, &protocolFactory{})
}

func (f *ReceiverFactory) ShouldRestart(newFactory transports.ReceiverFactory) bool {
return f.ReceiverFactory.ShouldRestart(newFactory.(*ReceiverFactory).ReceiverFactory)
}

// Register the transports
Expand Down

0 comments on commit c43f935

Please sign in to comment.