@@ -143,6 +143,8 @@ type service struct {
143143 driveMountStubs []MountableStubDrive
144144 exitAfterAllTasksDeleted bool // exit the VM and shim when all tasks are deleted
145145
146+ blockDeviceTasks map [string ]struct {}
147+
146148 cleanupErr error
147149 cleanupOnce sync.Once
148150
@@ -216,9 +218,10 @@ func NewService(shimCtx context.Context, id string, remotePublisher shim.Publish
216218
217219 config : cfg ,
218220
219- vmReady : make (chan struct {}),
220- jailer : newNoopJailer (shimCtx , logger , shimDir ),
221- fifos : make (map [string ]map [string ]cio.Config ),
221+ vmReady : make (chan struct {}),
222+ jailer : newNoopJailer (shimCtx , logger , shimDir ),
223+ blockDeviceTasks : make (map [string ]struct {}),
224+ fifos : make (map [string ]map [string ]cio.Config ),
222225 }
223226
224227 s .startEventForwarders (remotePublisher )
@@ -1188,6 +1191,7 @@ func (s *service) Create(requestCtx context.Context, request *taskAPI.CreateTask
11881191 logger .WithError (err ).Error ()
11891192 return nil , err
11901193 }
1194+ s .blockDeviceTasks [request .ID ] = struct {}{}
11911195 }
11921196
11931197 ociConfigBytes , err := hostBundleDir .OCIConfig ().Bytes ()
@@ -1278,11 +1282,14 @@ func (s *service) Delete(requestCtx context.Context, req *taskAPI.DeleteRequest)
12781282 if req .ExecID != "" {
12791283 return resp , nil
12801284 }
1285+
12811286 var result * multierror.Error
1282- // Trying to release stub drive for further reuse
1283- err = s .containerStubHandler .Release (requestCtx , req .ID , s .driveMountClient , s .machine )
1284- if err != nil {
1285- result = multierror .Append (result , errors .Wrapf (err , "failed to release stub drive for container: %s" , req .ID ))
1287+
1288+ if _ , contains := s .blockDeviceTasks [req .ID ]; contains {
1289+ // Trying to release stub drive for further reuse
1290+ if err := s .containerStubHandler .Release (requestCtx , req .ID , s .driveMountClient , s .machine ); err != nil {
1291+ result = multierror .Append (errors .Wrapf (err , "failed to release stub drive for container: %s" , req .ID ))
1292+ }
12861293 }
12871294
12881295 // Otherwise, delete the container
0 commit comments