Skip to content

Commit 614ca2e

Browse files
committed
fix: one more attempt to fix volume mount race on restart
The issue seems to be around still racy service restarts which leads to a potential hang on a conflicting state. By not re-using the mount request IDs on each restart, hopefully we can improve on it. Signed-off-by: Andrey Smirnov <[email protected]> (cherry picked from commit 8d12db4)
1 parent 4b86dfe commit 614ca2e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

internal/app/machined/pkg/system/service_runner.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212
"slices"
1313
"sync"
14+
"sync/atomic"
1415
"time"
1516

1617
"github.com/siderolabs/gen/xslices"
@@ -33,10 +34,11 @@ var WaitConditionCheckInterval = time.Second
3334
type ServiceRunner struct {
3435
mu sync.Mutex
3536

36-
runtime runtime.Runtime
37-
service Service
38-
id string
39-
instance *singleton
37+
runtime runtime.Runtime
38+
service Service
39+
id string
40+
instance *singleton
41+
generation atomic.Int64
4042

4143
state events.ServiceState
4244
events events.ServiceEvents
@@ -200,6 +202,8 @@ func (svcrunner *ServiceRunner) Run(notifyChannels ...chan<- struct{}) error {
200202
ctx, cancel := context.WithCancel(context.Background())
201203
defer cancel()
202204

205+
generation := svcrunner.generation.Add(1)
206+
203207
go func() {
204208
select {
205209
case <-ctx.Done():
@@ -229,7 +233,7 @@ func (svcrunner *ServiceRunner) Run(notifyChannels ...chan<- struct{}) error {
229233
volumeRequests := make([]volumeRequest, 0, len(volumeIDs))
230234

231235
for _, volumeID := range volumeIDs {
232-
requestID, err := svcrunner.createVolumeMountRequest(ctx, volumeID)
236+
requestID, err := svcrunner.createVolumeMountRequest(ctx, volumeID, generation)
233237
if err != nil {
234238
return err
235239
}

internal/app/machined/pkg/system/volumes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package system
77
import (
88
"context"
99
"fmt"
10+
"strconv"
1011

1112
"github.com/cosi-project/runtime/pkg/resource"
1213
"github.com/cosi-project/runtime/pkg/state"
@@ -15,10 +16,10 @@ import (
1516
"github.com/siderolabs/talos/pkg/machinery/resources/block"
1617
)
1718

18-
func (svcrunner *ServiceRunner) createVolumeMountRequest(ctx context.Context, volumeID string) (string, error) {
19+
func (svcrunner *ServiceRunner) createVolumeMountRequest(ctx context.Context, volumeID string, generation int64) (string, error) {
1920
st := svcrunner.runtime.State().V1Alpha2().Resources()
2021
requester := "service/" + svcrunner.id
21-
requestID := requester + "-" + volumeID
22+
requestID := requester + "-" + volumeID + "-" + strconv.FormatInt(generation, 10)
2223

2324
mountRequest := block.NewVolumeMountRequest(block.NamespaceName, requestID)
2425
mountRequest.TypedSpec().Requester = requester

0 commit comments

Comments
 (0)