mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 17:37:20 +00:00 
			
		
		
		
	shimv2/service: fix defer funtions never run with os.Exit()
os.Exit() will terminate program immediately, the defer functions won't be executed, so we add defer functions again before os.Exit(). Refer to https://pkg.go.dev/os#Exit Fixes: #3059 Signed-off-by: Binbin Zhang <binbin36520@gmail.com>
This commit is contained in:
		
				
					committed by
					
						 Samuel Ortiz
						Samuel Ortiz
					
				
			
			
				
	
			
			
			
						parent
						
							ac058b3897
						
					
				
				
					commit
					75bb340137
				
			| @@ -953,6 +953,12 @@ func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (_ * | ||||
| 	// exited when shimv2 terminated. Thus here to do the last cleanup of the hypervisor. | ||||
| 	syscall.Kill(int(s.hpid), syscall.SIGKILL) | ||||
|  | ||||
| 	// os.Exit() will terminate program immediately, the defer functions won't be executed, | ||||
| 	// so we add defer functions again before os.Exit(). | ||||
| 	// Refer to https://pkg.go.dev/os#Exit | ||||
| 	shimLog.WithField("container", r.ID).Debug("Shutdown() end") | ||||
| 	rpcDurationsHistogram.WithLabelValues("shutdown").Observe(float64(time.Since(start).Nanoseconds() / int64(time.Millisecond))) | ||||
|  | ||||
| 	os.Exit(0) | ||||
|  | ||||
| 	// This will never be called, but this is only there to make sure the | ||||
|   | ||||
		Reference in New Issue
	
	Block a user