Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Command failed: hdiutil detach #142

Closed
gmcdev opened this issue May 31, 2017 · 9 comments
Closed

Error: Command failed: hdiutil detach #142

gmcdev opened this issue May 31, 2017 · 9 comments
Labels

Comments

@gmcdev
Copy link

gmcdev commented May 31, 2017

I have been using this package, via electron-builder for almost a year with no problems. Recently, though, I started getting this error when it tries to unmount the temporary disk image.

Tracked it down to https://github.com/LinusU/node-appdmg/blob/master/lib/hdiutil.js#L64, exitCode is now just code, so the retry after one second was not happening.

However, even after I fixed that, it was still failing intermittently, so I put it on a setInterval to make 5 attempts on 2sec intervals, or until it succeeds.

Seems to be working.

@LinusU
Copy link
Owner

LinusU commented May 27, 2019

Probably need some kind of backoff with a retry-strategy here...

@aymather
Copy link

Came here from #143 I'd like to propose the fix I mentioned there.

Both fixes are definitely workarounds and probably not a long term solution. But I'd just like to get the ball rolling on this topic because this package is still breaking on my computer with this error.

Inside lib/hdiutil.js

Solution 1: Set a longer timeout to free up the resource (check out this forum for more information)

exports.detach = function (path, cb) {
  const args = ['detach', path]

  setTimeout(() => {
    util.sh('hdiutil', args, function (err) {
      if (err && err.exitCode === 16 && /Resource busy/.test(err.stderr)) {
        setTimeout(function () {
          util.sh('hdiutil', args, (err) => cb(err))
        }, 1000)
      } else {
        cb(err)
      }
    })
  }, 5000)
}

Solution 2: Forcibly detach the image (I tested this and it did not noticeably affect my app)

exports.detach = function (path, cb) {
  const args = ['detach', path, '-force']

    util.sh('hdiutil', args, function (err) {
      if (err && err.exitCode === 16 && /Resource busy/.test(err.stderr)) {
        setTimeout(function () {
          util.sh('hdiutil', args, (err) => cb(err))
        }, 1000)
      } else {
        cb(err)
      }
    })
}

@johanpoirier
Copy link

Any update on this? I have the same issue since I upgraded MacOS X to Catalina.

@jason-crawford-xio
Copy link

jason-crawford-xio commented Jan 20, 2023

Update: I'm withdrawing this suggestion. It assumed the unmounting was just for the sake of cleaning up at the end of the build, but upon further investigating, it appears that the creation of the dmg will not work if the drive is still mounted.

I'm experiencing this problem as well. The culprit in my case is a security scanner that is snooping the mount and preventing it from unmounting for a few minutes beyond the end of the failed build.

Ideally

  • the build would not have to wait for the unmount to succeed
  • the build would not terminate for the failing umount.

An alternative might be leave a command for the developer to invoke later to clean up once the scan is complete. And of course a warning message to suggest invoking it.

@LinusU
Copy link
Owner

LinusU commented Feb 1, 2023

This should be fixed by #214 released as 🚢 0.6.5 / 2023-02-01

@othyn
Copy link

othyn commented Jul 3, 2023

@LinusU hate to be the barer of bad news, but I don't think that fixed it.

I've made a bug report in a consuming library, https://github.com/sindresorhus/create-dmg which uses "appdmg": "^0.6.6", and I'm still getting this error which appears to originate from this library.

This only occured when moving from a macOS 12 to a macOS 13 runner for GitHub Actions, see:

https://github.com/othyn/macos-auto-clicker/actions/workflows/cicd.yml

You can see all the failed builds, with only one of them being randomly successful for both staging and main. I've not been able to decipher why that may be the case, as the log output is limited. I've diff'd the logs and nothing out of the ordinary is different. There doesn't appear to be any repeatable behavior between runs that I can pick appart as to why they'd fail. Yet the builds will randomly fail with:

[21:10:07]: $ ../node_modules/.bin/create-dmg ../build/AutoClicker.app --overwrite ../build
[21:10:08]: ▸ - Creating DMG
[21:10:14]: ▸ ✖ Building the DMG failed. Error: Command failed: hdiutil detach /Volumes/AutoClicker
[21:10:14]: ▸ hdiutil: detach failed - No such file or directory
[21:10:14]: Exit status of command '../node_modules/.bin/create-dmg ../build/AutoClicker.app --overwrite ../build' was 1 instead of 0.
- Creating DMG
✖ Building the DMG failed. Error: Command failed: hdiutil detach /Volumes/AutoClicker
hdiutil: detach failed - No such file or directory

The context of the action is running within Fastlane, which is just a build chain task runner for Xcode. sindresorhus/create-dmg is an opinionated wrapper around this library setting a load of defaults, with all errors being surfaced from this library.

Finding information online about this is pretty impossible, especially for debugging.

Any ideas?

@elneruda
Copy link

Hello @othyn

I'm currently encountering the same issue running a very close configuration

  • Github Action runs-on: macos-13
  • orchestrating the release with fastlane
  • running a tiny lane:
lane :dmg do 
  Dir.chdir("../") do
      sh("npm install -g appdmg")
      sh("appdmg fastlane/dmg.json MyApp.dmg")
  end
end
Error: Command failed: hdiutil detach /Volumes/MyApp
hdiutil: detach failed - No such file or directory

I'm very interested on evolution of this issue

@yuvalkarmi
Copy link

yuvalkarmi commented Jan 23, 2024

@LinusU I'm also experiencing the same issue, and it's happening completely randomly on github actions. about 1/5 builds randomly fails. Using 0.6.6.

Edit: I got it! Turns out the error is exactly what it says it is: in some cases, the volume has already been unmounted, so check before attempting to unmount. See here:

#229 (comment)

@othyn
Copy link

othyn commented Jan 24, 2024

@yuvalkarmi awesome that a fix has been submitted, still just need to wait for that to be merged though and then a dependency bump on this repo to use it.

@elneruda I gave up doing DMG builds a long time ago as there just wasn't a reliable option. I just zipped the app instead:

  # https://docs.fastlane.tools/actions/zip
  output_archive_path = zip(
    path: "build/AutoClicker.app",
    output_path: "build/AutoClicker.zip",
    verbose: true
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants