Skip to content

Commit caa7aa3

Browse files
Use timeout on rdb command to avoid block in command and process
1 parent 778b850 commit caa7aa3

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

daemon/nmon/main.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,20 +833,44 @@ func (t *Manager) loadPools() {
833833
return
834834
}
835835
renewed := make(map[string]any)
836+
837+
var renewedMu sync.Mutex
838+
var wg sync.WaitGroup
839+
836840
renew := func(p pool.Pooler) {
837-
ctx, cancel := context.WithTimeout(t.ctx, time.Minute)
841+
defer wg.Done()
842+
843+
ctx, cancel := context.WithTimeout(t.ctx, 10*time.Second)
838844
defer cancel()
845+
839846
poolName := p.Name()
840847
data := pool.GetStatus(ctx, p, true)
848+
849+
if ctx.Err() != nil {
850+
t.log.Warnf("loading pool '%s' status: %s", poolName, ctx.Err())
851+
return
852+
}
853+
t.log.Infof("pool '%s' status loaded", poolName)
854+
855+
renewedMu.Lock()
841856
renewed[poolName] = nil
857+
renewedMu.Unlock()
858+
842859
pool.StatusData.Set(poolName, t.localhost, data.DeepCopy())
843860
t.publisher.Pub(&msgbus.NodePoolStatusUpdated{Node: t.localhost, Name: poolName, Value: data}, t.labelLocalhost)
861+
844862
}
845863
for _, p := range n.Pools() {
846-
renew(p)
864+
wg.Add(1)
865+
go renew(p)
847866
}
867+
868+
wg.Wait()
848869
for _, e := range pool.StatusData.GetByNode(t.localhost) {
849-
if _, ok := renewed[e.Name]; !ok {
870+
renewedMu.Lock()
871+
_, ok := renewed[e.Name]
872+
renewedMu.Unlock()
873+
if !ok {
850874
pool.StatusData.Unset(e.Name, t.localhost)
851875
}
852876
}

drivers/resdiskrados/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77
"slices"
8+
"time"
9+
10+
"github.com/rs/zerolog"
811

912
"github.com/opensvc/om3/v3/core/actionrollback"
1013
"github.com/opensvc/om3/v3/core/datarecv"
@@ -17,7 +20,6 @@ import (
1720
"github.com/opensvc/om3/v3/util/hostname"
1821
"github.com/opensvc/om3/v3/util/sizeconv"
1922
"github.com/opensvc/om3/v3/util/udevadm"
20-
"github.com/rs/zerolog"
2123
)
2224

2325
type (
@@ -79,6 +81,10 @@ type (
7981
}
8082
)
8183

84+
const (
85+
DefaultCommandTimeout = 10 * time.Second
86+
)
87+
8288
func New() resource.Driver {
8389
t := &T{}
8490
return t
@@ -116,6 +122,7 @@ func (t *T) mapDevice(ctx context.Context) error {
116122
args = append(args, "map", t.Name)
117123
cmd := command.New(
118124
command.WithContext(ctx),
125+
command.WithTimeout(DefaultCommandTimeout),
119126
command.WithName("rbd"),
120127
command.WithArgs(args),
121128
command.WithLogger(t.Log()),
@@ -144,6 +151,7 @@ func (t *T) unmapDevice(ctx context.Context) error {
144151
args = append(args, "unmap", t.Name)
145152
cmd := command.New(
146153
command.WithContext(ctx),
154+
command.WithTimeout(DefaultCommandTimeout),
147155
command.WithName("rbd"),
148156
command.WithArgs(args),
149157
command.WithLogger(t.Log()),
@@ -166,6 +174,7 @@ func (t *T) createDevice(ctx context.Context) error {
166174
args = append(args, "create", "--size", fmt.Sprintf("%dB", bytes), t.Name)
167175
cmd := command.New(
168176
command.WithContext(ctx),
177+
command.WithTimeout(DefaultCommandTimeout),
169178
command.WithName("rbd"),
170179
command.WithArgs(args),
171180
command.WithLogger(t.Log()),
@@ -188,6 +197,7 @@ func (t *T) removeDevice(ctx context.Context) error {
188197
args = append(args, "remove", t.Name)
189198
cmd := command.New(
190199
command.WithContext(ctx),
200+
command.WithTimeout(DefaultCommandTimeout),
191201
command.WithName("rbd"),
192202
command.WithArgs(args),
193203
command.WithLogger(t.Log()),
@@ -217,6 +227,7 @@ func (t *T) lockDevice(ctx context.Context) error {
217227
}
218228
cmd := command.New(
219229
command.WithContext(ctx),
230+
command.WithTimeout(DefaultCommandTimeout),
220231
command.WithName("rbd"),
221232
command.WithArgs(args),
222233
command.WithLogger(t.Log()),
@@ -246,6 +257,7 @@ func (t *T) unlockDevice(ctx context.Context) error {
246257
}
247258
cmd := command.New(
248259
command.WithContext(ctx),
260+
command.WithTimeout(DefaultCommandTimeout),
249261
command.WithName("rbd"),
250262
command.WithArgs(args),
251263
command.WithLogger(t.Log()),
@@ -271,6 +283,7 @@ func (t *T) deviceInfo(ctx context.Context) (*RBDInfo, error) {
271283
args = append(args, "info", t.Name, "--format", "json")
272284
cmd := command.New(
273285
command.WithContext(ctx),
286+
command.WithTimeout(DefaultCommandTimeout),
274287
command.WithName("rbd"),
275288
command.WithArgs(args),
276289
command.WithLogger(t.Log()),
@@ -299,6 +312,7 @@ func (t *T) listLocks(ctx context.Context) ([]RBDLock, error) {
299312
args = append(args, "lock", "list", t.Name, "--format", "json")
300313
cmd := command.New(
301314
command.WithContext(ctx),
315+
command.WithTimeout(DefaultCommandTimeout),
302316
command.WithName("rbd"),
303317
command.WithArgs(args),
304318
command.WithLogger(t.Log()),
@@ -324,6 +338,7 @@ func (t *T) listDevices(ctx context.Context) ([]RBDMap, error) {
324338
args = append(args, "device", "list", "--format", "json")
325339
cmd := command.New(
326340
command.WithContext(ctx),
341+
command.WithTimeout(DefaultCommandTimeout),
327342
command.WithName("rbd"),
328343
command.WithArgs(args),
329344
command.WithLogger(t.Log()),

0 commit comments

Comments
 (0)