| author | |
| committer | |
| log | 3179871dfe597f763b9fb45590b07a0679b0a628 |
| tree | 5651e389b4583ca8906f7b3cae54ba75031a28f9 |
| parent | 4b9b72a97a15043281000b19a4b154ff209d1355 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Accept the CLR mapping of a missing Task Scheduler task and retry older worker
cleanup through its pinned assembly. Early desktop startup must not leave a VM
permanently requiring recovery.
Assisted-by: gpt-6.1-sol3 files changed, 43 insertions(+), 7 deletions(-)
guest/computer-windows.cs+1-1| ... | ... | @@ -196,7 +196,7 @@ public static class ComputerWorker { |
| 196 | 196 | service.Connect(null,null,null,null); |
| 197 | 197 | dynamic folder=service.GetFolder("\\"); |
| 198 | 198 | try { folder.DeleteTask("SnowglobeComputer-"+System.IO.Path.GetFileName(directory),0); } |
| 199 | catch(COMException error) { if(error.ErrorCode!=unchecked((int)0x80070002))throw; } | |
| 199 | catch(Exception error) { if(error.HResult!=unchecked((int)0x80070002))throw; } | |
| 200 | 200 | if(!keepSpawn && System.IO.Directory.Exists(directory))System.IO.Directory.Delete(directory,true); |
| 201 | 201 | } |
| 202 | 202 | static object Target(System.Windows.Automation.AutomationElement node) { |
tools/computer-test.py+27| ... | ... | @@ -363,6 +363,33 @@ class GuestCancellation(unittest.TestCase): |
| 363 | 363 | self.assertEqual(result['stdout'], 'ready') |
| 364 | 364 | self.assertEqual([call.args[2][0] for call in execute.call_args_list], ['--prepare', '--launch', '--cleanup']) |
| 365 | 365 | |
| 366 | def test_failed_native_cleanup_recovers_through_the_pinned_worker(self): | |
| 367 | operation = {'platform': 'windows', 'id': 'a' * 32, | |
| 368 | 'worker': 'C:\\ProgramData\\SnowglobeComputer\\worker-previous.exe'} | |
| 369 | computer.record_operation('fixture', operation) | |
| 370 | with patch.object(computer, 'guest_exec', side_effect=ValueError('Worker exited 1')), patch.object(computer, 'powershell', return_value=b'') as fallback: | |
| 371 | computer.finish_operation('fixture', operation) | |
| 372 | script = fallback.call_args.args[1] | |
| 373 | self.assertIn("LoadFrom('" + operation['worker'] + "')", script) | |
| 374 | self.assertIn('[ComputerProcess]::Stop', script) | |
| 375 | self.assertFalse((computer.vms.DISKS / 'fixture' / 'computer-operation.json').exists()) | |
| 376 | ||
| 377 | def test_failed_native_and_fallback_cleanup_preserves_recovery(self): | |
| 378 | operation = {'platform': 'windows', 'id': 'a' * 32, 'worker': 'previous.exe'} | |
| 379 | computer.record_operation('fixture', operation) | |
| 380 | with patch.object(computer, 'guest_exec', side_effect=ValueError('Worker exited 1')), patch.object(computer, 'powershell', side_effect=ValueError('Disconnected')): | |
| 381 | with self.assertRaises(BlockingIOError): | |
| 382 | computer.finish_operation('fixture', operation) | |
| 383 | self.assertEqual(json.loads((computer.vms.DISKS / 'fixture' / 'computer-operation.json').read_text()), operation) | |
| 384 | ||
| 385 | def test_spawn_cleanup_fallback_keeps_the_process_running(self): | |
| 386 | operation = {'platform': 'windows', 'id': 'a' * 32, 'worker': 'previous.exe', 'keep_spawn': True} | |
| 387 | computer.record_operation('fixture', operation) | |
| 388 | with patch.object(computer, 'guest_exec', side_effect=ValueError('Worker exited 1')), patch.object(computer, 'powershell', return_value=b'') as fallback: | |
| 389 | computer.finish_operation('fixture', operation) | |
| 390 | self.assertNotIn('[ComputerProcess]::Stop', fallback.call_args.args[1]) | |
| 391 | self.assertNotIn('$t.Stop(0)', fallback.call_args.args[1]) | |
| 392 | ||
| 366 | 393 | def test_linux_stops_the_exact_request_unit_with_a_fresh_cleanup_budget(self): |
| 367 | 394 | units = [] |
| 368 | 395 | def execute(name, executable, arguments, data=None, **kwargs): |
tools/vm-computer.py+15-6| ... | ... | @@ -372,20 +372,29 @@ def finish_operation(name, operation): |
| 372 | 372 | json.dumps({'_stop': operation['id']}).encode(), timeout=18) |
| 373 | 373 | elif operation.get('worker'): |
| 374 | 374 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + operation['id'] |
| 375 | guest_exec(name, operation['worker'], ['--release' if operation.get('keep_spawn') else '--cleanup', directory], timeout=58) | |
| 376 | else: | |
| 375 | try: | |
| 376 | guest_exec(name, operation['worker'], ['--release' if operation.get('keep_spawn') else '--cleanup', directory], timeout=58) | |
| 377 | except ValueError: | |
| 378 | pass | |
| 379 | else: | |
| 380 | (vms.DISKS / name / 'computer-operation.json').unlink() | |
| 381 | return | |
| 382 | if operation['platform'] == 'windows': | |
| 377 | 383 | run = operation['id'] |
| 378 | 384 | directory = 'C:\\ProgramData\\SnowglobeComputer\\' + run |
| 379 | 385 | cleanup = "$ErrorActionPreference='Stop';$d='"+directory+"';" |
| 380 | 386 | cleanup += "if(Test-Path -LiteralPath ($d+'\\request.json')){Remove-Item -LiteralPath ($d+'\\request.json') -Force};" |
| 381 | 387 | cleanup += "$s=New-Object -ComObject Schedule.Service;$s.Connect();$f=$s.GetFolder('\\');" |
| 382 | cleanup += "$t=$f.GetTasks(1) | Where-Object {$_.Name -eq 'SnowglobeComputer-"+run+"'};if($t){" | |
| 388 | cleanup += "$t=$f.GetTasks(1) | Where-Object {$_.Name -eq 'SnowglobeComputer-"+run+"'};" | |
| 383 | 389 | if not operation.get('keep_spawn'): |
| 390 | if operation.get('worker'): | |
| 391 | cleanup += "[Reflection.Assembly]::LoadFrom('"+operation['worker']+"')|Out-Null;[ComputerProcess]::Stop($d+'\\request.json');" | |
| 384 | 392 | cleanup += "$workers=@(Get-WmiObject Win32_Process | Where-Object {$_.CommandLine -like ('*'+$d+'\\request.json*')} | ForEach-Object {$p=Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue;if($p){$null=$p.Handle;$p}});" |
| 385 | cleanup += "[Reflection.Assembly]::LoadFrom($t.Definition.Actions.Item(1).Path)|Out-Null;[ComputerProcess]::Stop($d+'\\request.json');" | |
| 386 | cleanup += "$t.Stop(0);while($t.State -eq 4){Start-Sleep -Milliseconds 100};" | |
| 393 | if not operation.get('worker'): | |
| 394 | cleanup += "if($t){[Reflection.Assembly]::LoadFrom($t.Definition.Actions.Item(1).Path)|Out-Null;[ComputerProcess]::Stop($d+'\\request.json')};" | |
| 395 | cleanup += "if($t){$t.Stop(0);while($t.State -eq 4){Start-Sleep -Milliseconds 100}};" | |
| 387 | 396 | cleanup += "foreach($p in $workers){if(!$p.WaitForExit(10000)){throw 'Process cleanup failed'};$p.Dispose()};" |
| 388 | cleanup += "$f.DeleteTask('SnowglobeComputer-"+run+"',0)};" | |
| 397 | cleanup += "if($t){$f.DeleteTask('SnowglobeComputer-"+run+"',0)};" | |
| 389 | 398 | if not operation.get('keep_spawn'): |
| 390 | 399 | cleanup += "if(Test-Path -LiteralPath $d){Remove-Item -LiteralPath $d -Recurse -Force}" |
| 391 | 400 | powershell(name, cleanup, timeout=58) |