Skip to content

Commit

Permalink
Fix #64: Try to mitigate failing to eject secondary disk
Browse files Browse the repository at this point in the history
This will hopefully fix or mitigate the following error that occurs
when trying to eject the secondary disk:

```
hdiutil: couldn't eject "disk2" - Resource busy
```
  • Loading branch information
jacob-carlborg committed Nov 3, 2023
1 parent 7de7abf commit 20b4985
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- FreeBSD jobs occasionally fail when ejecting the disk ([#64](https://github.com/cross-platform-actions/action/issues/64))

## [0.21.0] - 2023-10-26
### Added
- Add support for OpenBSD 7.4 ([openbsd-builder#15](https://github.com/cross-platform-actions/openbsd-builder/issues/15))
Expand Down
16 changes: 15 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/resource_disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as exec from '@actions/exec'
import {Action} from './action/action'
import {execWithOutput} from './utility'
import type {OperatingSystem} from './operating_system'
import {wait} from './wait'

export default abstract class ResourceDisk {
protected readonly operatingSystem: OperatingSystem
Expand Down Expand Up @@ -124,7 +125,21 @@ class MacOs extends ResourceDisk {
}

override async detachDevice(devicePath: string): Promise<void> {
await exec.exec('hdiutil', ['detach', devicePath])
const maxRetries = 150
const waitTimeSeconds = 1

for (let i = 0; i < maxRetries; i++) {
try {
await exec.exec('hdiutil', ['detach', devicePath])
return
} catch (error: unknown) {
const err = error as Error
core.debug(`Failed to detach device: ${err.message}`)
await wait(waitTimeSeconds * 1000)
}
}

core.error(`Failed to detach device after ${maxRetries} retries`)
}
}

Expand Down

0 comments on commit 20b4985

Please sign in to comment.