Skip to content

Commit

Permalink
Merge pull request #366 from hellofresh/hotfix/listener
Browse files Browse the repository at this point in the history
PT-2147 Fixed configuration listener that made API stuck
  • Loading branch information
vgarvardt authored Oct 17, 2018
2 parents 1ffb8c8 + 3a8af07 commit 0961171
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Unreleased

# 3.8.4

## Fixed
- Fixed configuration listener that made API stuck

# 3.8.3

## Added
- Support b3 http propagation format for jaeger

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ all: clean deps test build
deps:
@echo "$(OK_COLOR)==> Installing dependencies$(NO_COLOR)"
@go get -u github.com/golang/dep/cmd/dep
@go get -u github.com/golang/lint/golint
@go get -u golang.org/x/lint/golint
@go get -u github.com/DATA-DOG/godog/cmd/godog
@dep ensure -v -vendor-only

Expand Down
42 changes: 25 additions & 17 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,35 @@ func (s *Server) startProvider(ctx context.Context) error {
return errors.Wrap(err, "could not start Janus web API")
}

if listener, ok := s.provider.(api.Listener); ok {
go func() {
ch := make(chan api.ConfigurationMessage)
// We're listening to the configuration changes in any case, even if provider does not implement Listener,
// so we can use "file" storage as memory - all the persistent definitions are loaded on startup,
// but then API allows to manipulate proxies in memory. Otherwise api calls just stuck because channel is busy.
go func() {
ch := make(chan api.ConfigurationMessage)
listener, providerIsListener := s.provider.(api.Listener)
if providerIsListener {
listener.Listen(ctx, ch)
for {
select {
case c, more := <-s.webServer.ConfigurationChan:
if !more {
return
}

s.updateConfigurations(c)
s.handleEvent(s.currentConfigurations)
ch <- c
case <-ctx.Done():
close(ch)
}

for {
select {
case c, more := <-s.webServer.ConfigurationChan:
if !more {
return
}

s.updateConfigurations(c)
s.handleEvent(s.currentConfigurations)

if providerIsListener {
ch <- c
}
case <-ctx.Done():
close(ch)
return
}
}()
}
}
}()

if watcher, ok := s.provider.(api.Watcher); ok {
watcher.Watch(ctx, s.configurationChan)
Expand Down

0 comments on commit 0961171

Please sign in to comment.