提交记录修改internal/workbench/control_recovery_test.go+23 −0看文件
修改internal/workbench/desktop.go+6 −1看文件
| @@ -211,3 +211,26 @@ func TestDesktopWaitsForRetiringController(t *testing.T) { | ||
| 211 | 211 | t.Fatalf("did not resume after shutdown: %v", err) |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 新增: | |
| 215 | 新增:func TestPrepareUpdateWaitsForRetiringController(t *testing.T) { | |
| 216 | 新增: profile := t.TempDir() | |
| 217 | 新增: lock, err := openControllerLock(profile, os.O_CREATE|os.O_RDWR) | |
| 218 | 新增: if err != nil { | |
| 219 | 新增: t.Fatal(err) | |
| 220 | 新增: } | |
| 221 | 新增: defer lock.Close() | |
| 222 | 新增: if err := lockController(lock); err != nil { | |
| 223 | 新增: t.Fatal(err) | |
| 224 | 新增: } | |
| 225 | 新增: // Shutdown has removed control.json but has not released the profile yet. | |
| 226 | 新增: released := make(chan struct{}) | |
| 227 | 新增: go func() { time.Sleep(100 * time.Millisecond); _ = unlockController(lock); close(released) }() | |
| 228 | 新增: defer func() { <-released }() | |
| 229 | 新增: result, err := PrepareUpdate(filepath.Join(profile, "config.json"), false) | |
| 230 | 新增: if err != nil || result.Status != "prepared" { | |
| 231 | 新增: t.Fatalf("retiring controller prevented update: %+v %v", result, err) | |
| 232 | 新增: } | |
| 233 | 新增: if !controllerLockFree(profile) { | |
| 234 | 新增: t.Fatal("update accepted before the controller released its lock") | |
| 235 | 新增: } | |
| 236 | 新增:} | |
| @@ -243,7 +243,12 @@ func desktopLaunch(profile string, gateway bool, options DesktopOptions, start f | ||
| 243 | 243 | // PrepareUpdate is shared by the explicit migration button and the installer. |
| 244 | 244 | // It returns only after the old service has released its profile lock. |
| 245 | 245 | func PrepareUpdate(configPath string, stop bool) (DesktopResult, error) { |
| 246 | 删除: c, err := connectController(filepath.Dir(configPath)) | |
| 246 | 新增: // A closing controller stops accepting requests before releasing its lock. | |
| 247 | 新增: // Use the same bounded retirement wait as desktop startup; the lock and VM | |
| 248 | 新增: // checks below still decide whether replacing the application is safe. | |
| 249 | 新增: ctx, cancel := context.WithTimeout(context.Background(), 12*time.Second) | |
| 250 | 新增: defer cancel() | |
| 251 | 新增: c, err := waitControllerReady(ctx, filepath.Dir(configPath)) | |
| 247 | 252 | if errors.Is(err, errControllerUnavailable) { |
| 248 | 253 | lock, lockErr := openControllerLock(filepath.Dir(configPath), os.O_RDWR) |
| 249 | 254 | if lockErr == nil { |

