@@ -4140,17 +4140,28 @@ async fn remove_docker_channel_volume_by_id(
41404140}
41414141
41424142async fn remove_docker_volume ( docker : & Docker , name : & str ) -> Result < ( ) , Status > {
4143- docker
4144- . remove_volume ( name, None :: < bollard:: query_parameters:: RemoveVolumeOptions > )
4145- . await
4146- . or_else ( |error| {
4147- if is_not_found_error ( & error) {
4148- Ok ( ( ) )
4149- } else {
4150- Err ( error)
4143+ // Docker can acknowledge removal of the last container before releasing
4144+ // its volume mount. Retry only that transient 409; other conflicts and
4145+ // daemon errors should still fail the sandbox deletion.
4146+ const MAX_ATTEMPTS : usize = 12 ;
4147+ for attempt in 1 ..=MAX_ATTEMPTS {
4148+ match docker
4149+ . remove_volume ( name, None :: < bollard:: query_parameters:: RemoveVolumeOptions > )
4150+ . await
4151+ {
4152+ Ok ( ( ) ) => return Ok ( ( ) ) ,
4153+ Err ( error) if is_not_found_error ( & error) => return Ok ( ( ) ) ,
4154+ Err ( error) if is_volume_in_use_error ( & error) && attempt < MAX_ATTEMPTS => {
4155+ tokio:: time:: sleep ( Duration :: from_millis ( 250 ) ) . await ;
41514156 }
4152- } )
4153- . map_err ( |error| Status :: internal ( format ! ( "remove Docker sandbox runtime volume: {error}" ) ) )
4157+ Err ( error) => {
4158+ return Err ( Status :: internal ( format ! (
4159+ "remove Docker sandbox runtime volume: {error}"
4160+ ) ) ) ;
4161+ }
4162+ }
4163+ }
4164+ unreachable ! ( "the final volume removal attempt returns a result" )
41544165}
41554166
41564167fn sandbox_token_host_path (
@@ -6525,6 +6536,16 @@ fn is_removal_in_progress_error(err: &BollardError) -> bool {
65256536 )
65266537}
65276538
6539+ fn is_volume_in_use_error ( err : & BollardError ) -> bool {
6540+ matches ! (
6541+ err,
6542+ BollardError :: DockerResponseServerError {
6543+ status_code: 409 ,
6544+ message,
6545+ } if message. contains( "volume is in use" )
6546+ )
6547+ }
6548+
65286549fn is_not_modified_error ( err : & BollardError ) -> bool {
65296550 matches ! (
65306551 err,
0 commit comments