Skip to content

Commit 17c55df

Browse files
author
Fabian Holler
committed
remove tracking stopped containers as dying
Do not mark containers as dying after they have been stopped. The mechanic causes that when a single container is restarted it is not registered again. The containers is marked as dying until ttl-dying-cleanup expired. If the container is restarted before the TTL expires it ignored and not registered again. Containers are also only unmarked as dying when bridge.add() is called, if this did not happen despite the TTL expires and the container was restarted it was also not registered again. I guess the dying state was introduced to prevent that a container is reregistered while it is being shutdown. Because Sync() was changed to only consider containers in running state it can not happen anymore. The ttl-dying-cleanup config option is removed.
1 parent 103eadb commit 17c55df

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
lines changed

bridge/bridge.go

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14-
"time"
1514

1615
dockerapi "github.com/fsouza/go-dockerclient"
1716
)
@@ -20,12 +19,11 @@ var serviceIDPattern = regexp.MustCompile(`^(.+?):([a-zA-Z0-9][a-zA-Z0-9_.-]+):[
2019

2120
type Bridge struct {
2221
sync.Mutex
23-
registry RegistryAdapter
24-
docker *dockerapi.Client
25-
services map[string][]*Service
26-
deadContainers map[string]*DeadContainer
27-
dyingContainers map[string]time.Time
28-
config Config
22+
registry RegistryAdapter
23+
docker *dockerapi.Client
24+
services map[string][]*Service
25+
deadContainers map[string]*DeadContainer
26+
config Config
2927
}
3028

3129
func New(docker *dockerapi.Client, adapterUri string, config Config) (*Bridge, error) {
@@ -40,12 +38,11 @@ func New(docker *dockerapi.Client, adapterUri string, config Config) (*Bridge, e
4038

4139
log.Println("Using", uri.Scheme, "adapter:", uri)
4240
return &Bridge{
43-
docker: docker,
44-
config: config,
45-
registry: factory.New(uri),
46-
services: make(map[string][]*Service),
47-
deadContainers: make(map[string]*DeadContainer),
48-
dyingContainers: make(map[string]time.Time),
41+
docker: docker,
42+
config: config,
43+
registry: factory.New(uri),
44+
services: make(map[string][]*Service),
45+
deadContainers: make(map[string]*DeadContainer),
4946
}, nil
5047
}
5148

@@ -179,11 +176,6 @@ func (b *Bridge) Sync(quiet bool) {
179176
}
180177

181178
func (b *Bridge) add(containerId string, quiet bool) {
182-
if _, ok := b.dyingContainers[containerId]; ok {
183-
log.Println("container, ", containerId[:12], ", is dying, ignoring")
184-
return
185-
}
186-
187179
if d := b.deadContainers[containerId]; d != nil {
188180
b.services[containerId] = d.Services
189181
delete(b.deadContainers, containerId)
@@ -384,7 +376,6 @@ func (b *Bridge) remove(containerId string, deregister bool) {
384376
b.deadContainers[containerId] = &DeadContainer{b.config.RefreshTtl, b.services[containerId]}
385377
}
386378
delete(b.services, containerId)
387-
b.markContainerAsDying(containerId)
388379
}
389380

390381
// bit set on ExitCode if it represents an exit via a signal
@@ -418,18 +409,6 @@ func (b *Bridge) shouldRemove(containerId string) bool {
418409
return false
419410
}
420411

421-
func (b *Bridge) markContainerAsDying(containerId string) {
422-
// cleanup after CleanupDyingTtl
423-
for containerId, t := range b.dyingContainers {
424-
if time.Since(t) >= time.Millisecond*time.Duration(b.config.CleanupDyingTtl) {
425-
delete(b.dyingContainers, containerId)
426-
}
427-
}
428-
429-
// mark container as "dying"
430-
b.dyingContainers[containerId] = time.Now()
431-
}
432-
433412
var Hostname string
434413

435414
func init() {

bridge/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type Config struct {
2929
RefreshInterval int
3030
DeregisterCheck string
3131
Cleanup bool
32-
CleanupDyingTtl int
3332
}
3433

3534
type Service struct {

registrator.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var (
3434
retryAttempts = flag.Int("retry-attempts", 0, "Max retry attempts to establish a connection with the backend. Use -1 for infinite retries")
3535
retryInterval = flag.Int("retry-interval", 2000, "Interval (in millisecond) between retry-attempts.")
3636
cleanup = flag.Bool("cleanup", false, "Remove dangling services")
37-
cleanupDyingTtl = flag.Int("ttl-dying-cleanup", 60000, "TTL (in millisecond) for cleaning dying containers cache")
3837
)
3938

4039
func assert(err error) {
@@ -110,7 +109,6 @@ func main() {
110109
RefreshInterval: *refreshInterval,
111110
DeregisterCheck: *deregister,
112111
Cleanup: *cleanup,
113-
CleanupDyingTtl: *cleanupDyingTtl,
114112
})
115113

116114
assert(err)

0 commit comments

Comments
 (0)