Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix k8s panic #900

Merged
merged 2 commits into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ address = ":8080"
# To enable digest auth on the webui
# with 2 user/realm/pass: test:traefik:test and test2:traefik:test2
# You can use htdigest to generate those ones
# [web.auth.basic]
# [web.auth.digest]
# users = ["test:traefik:a2688e031edb4be6a3797f3882655c05 ", "test2:traefik:518845800f9e2bfb1f1f740ec24f074e"]

```
Expand Down
23 changes: 15 additions & 8 deletions provider/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"github.com/containous/traefik/log"
"github.com/containous/traefik/safe"
"github.com/parnurzeal/gorequest"
"net/http"
"net/url"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (c *clientImpl) WatchAll(labelSelector string, stopCh <-chan bool) (chan in
if err != nil {
return watchCh, errCh, fmt.Errorf("failed to create watch: %v", err)
}
go func() {
safe.Go(func() {
defer close(watchCh)
defer close(errCh)
defer close(stopIngresses)
Expand Down Expand Up @@ -188,7 +189,7 @@ func (c *clientImpl) WatchAll(labelSelector string, stopCh <-chan bool) (chan in
watchCh <- event
}
}
}()
})

return watchCh, errCh, nil
}
Expand Down Expand Up @@ -268,11 +269,16 @@ func (c *clientImpl) watch(url string, labelSelector string, stopCh <-chan bool)
return watchCh, errCh, fmt.Errorf("failed to do watch request: GET %q: %v", url, err)
}

go func() {
safe.Go(func() {
EndCh := make(chan bool, 1)
defer close(watchCh)
defer close(errCh)
go func() {
defer close(EndCh)
safe.Go(func() {
defer res.Body.Close()
defer func() {
EndCh <- true
}()
for {
var eventList interface{}
if err := json.NewDecoder(res.Body).Decode(&eventList); err != nil {
Expand All @@ -283,11 +289,12 @@ func (c *clientImpl) watch(url string, labelSelector string, stopCh <-chan bool)
}
watchCh <- eventList
}
}()
})
<-stopCh
go func() {
safe.Go(func() {
cancel() // cancel watch request
}()
}()
})
<-EndCh
})
return watchCh, errCh, nil
}
2 changes: 1 addition & 1 deletion traefik.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
# To enable digest auth on the webui
# with 2 user/realm/pass: test:traefik:test and test2:traefik:test2
# You can use htdigest to generate those ones
# [web.auth.basic]
# [web.auth.digest]
# users = ["test:traefik:a2688e031edb4be6a3797f3882655c05 ", "test2:traefik:518845800f9e2bfb1f1f740ec24f074e"]


Expand Down