Skip to content

Commit

Permalink
bpf: Retry opening map after initial error
Browse files Browse the repository at this point in the history
Current code used sync.Once and only attempted opening the map once using
sync.Once. Subsequent tried to open the map would always fail without
ever retrying, i.e. the initial failure always became a permanent failure.

Fixes: #2965

Reported-by: @mrdima
Signed-off-by: Thomas Graf <thomas@cilium.io>
  • Loading branch information
tgraf committed Mar 6, 2018
1 parent 04b1a70 commit 47e01eb
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions pkg/bpf/map.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2017 Authors of Cilium
// Copyright 2016-2018 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -120,6 +120,9 @@ type Map struct {
once sync.Once
lock lock.RWMutex

// openLock serializes calls to Map.Open()
openLock lock.Mutex

// NonPersistent is true if the map does not contain persistent data
// and should be removed on startup.
NonPersistent bool
Expand Down Expand Up @@ -353,25 +356,24 @@ reopen:
}

func (m *Map) Open() error {
var err error
m.once.Do(func() {
if m.fd != 0 {
err = nil
return
}
m.openLock.Lock()
defer m.openLock.Unlock()

if err = m.setPathIfUnset(); err != nil {
return
}
var fd int
fd, err = ObjGet(m.path)
if err != nil {
return
}
if m.fd != 0 {
return nil
}

m.fd = fd
})
return err
if err := m.setPathIfUnset(); err != nil {
return err
}

fd, err := ObjGet(m.path)
if err != nil {
return err
}

m.fd = fd
return nil
}

func (m *Map) Close() error {
Expand Down

0 comments on commit 47e01eb

Please sign in to comment.