Skip to content

Commit

Permalink
MF-29 - goroutine in some cases never process channel messages (#30)
Browse files Browse the repository at this point in the history
* fixed bug caused by reference type param that is overwritten by another goroutine

Signed-off-by: PricelessRabbit <[email protected]>

* refactored code to always use a single reference of route

Signed-off-by: PricelessRabbit <[email protected]>
  • Loading branch information
pricelessrabbit authored Nov 14, 2020
1 parent cdbc6f2 commit c462df2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/export/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type Route struct {
pub messages.Publisher
}

func NewRoute(rc config.Route, log logger.Logger, pub messages.Publisher) Route {
func NewRoute(rc config.Route, log logger.Logger, pub messages.Publisher) *Route {
w := rc.Workers
if w == 0 {
w = workers
}
r := Route{
r := &Route{
NatsTopic: rc.NatsTopic + "." + NatsAll,
MqttTopic: rc.MqttTopic,
Subtopic: rc.SubTopic,
Expand Down
8 changes: 4 additions & 4 deletions pkg/export/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type exporter struct {
id string
mqtt mqtt.Client
cfg config.Config
consumers map[string]Route
consumers map[string]*Route
logger logger.Logger
connected chan bool
status uint32
Expand All @@ -62,7 +62,7 @@ var errNoRoutesConfigured = errors.New("No routes configured")

// New create new instance of export service
func New(c config.Config, l logger.Logger) (Service, error) {
routes := make(map[string]Route)
routes := make(map[string]*Route)
id := fmt.Sprintf("export-%s", c.MQTT.Username)

e := exporter{
Expand All @@ -81,7 +81,7 @@ func New(c config.Config, l logger.Logger) (Service, error) {

// Start method loads route configuration
func (e *exporter) Start(queue string) errors.Error {
var route Route
var route *Route
for _, r := range e.cfg.Routes {
route = e.newRoute(r)
if !e.validateSubject(route.NatsTopic) {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (e *exporter) Logger() logger.Logger {
return e.logger
}

func (e *exporter) newRoute(r config.Route) Route {
func (e *exporter) newRoute(r config.Route) *Route {
return NewRoute(r, e.logger, e)
}

Expand Down

0 comments on commit c462df2

Please sign in to comment.