Skip to content

#142: fixes hdiutil err.exitCode->err.code, adds setInterval#143

Closed
gmcdev wants to merge 4 commits intomasterfrom
unknown repository
Closed

#142: fixes hdiutil err.exitCode->err.code, adds setInterval#143
gmcdev wants to merge 4 commits intomasterfrom
unknown repository

Conversation

@gmcdev
Copy link
Copy Markdown

@gmcdev gmcdev commented May 31, 2017

Interval is at 2sec…up to 5 tries before giving up.

Issue: #142

@gmcdev gmcdev closed this Sep 6, 2017
@LinusU
Copy link
Copy Markdown
Owner

LinusU commented Sep 10, 2017

Sorry for not getting to this earlier :(

I have a branch where I have changed pretty much everything to use promises and there the plan was to use p-retry to do this.

I'm very interested in the err.exitCode vs err.code though? Is it broken for you as it is now? Which platform/version of Node.js are you using?

@gmcdev
Copy link
Copy Markdown
Author

gmcdev commented Sep 11, 2017 via email

@agustincelentano
Copy link
Copy Markdown

it is happening to me. I was working but suddently it started to occur.. any update / work around?

@aymather
Copy link
Copy Markdown

aymather commented Jan 16, 2020

I don't know if anybody is still having this problem, but I came across this as I was struggling with the same thing. Whenever I was using electron-installer-dmg I was getting the following error: Error: Command failed: hdiutil detach /Volumes/Electron-React hdiutil: couldn't unmount "disk2" - Resource busy

Where disk* was incrementing each time.

I found this forum that explained that "The only reason unmounting might fail is that other software is accessing the disk image during construction, which really shouldn't be happening. If that's the case, the attempt to detach non-forcibly will fail and we will force a detach instead."

Your workaround address, what I think is, the core issue of: appdmg is trying to access the .dmg during construction. So your interval of 2 seconds was (i'm betting) allmmoostt enough to allow it to fully build, which is why it was working every once in a while and failing other times.

I tested this by adding a setTimeout of 5 seconds before this function is to run, and my code never failed again. Even though setting a Timeout is rather simple, here's how I did it:

Inside: lib/hdiutil.js

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);
}

I'm looking into figuring out a way to keep track of the .dmg build process, to see if we can tell when it's done, so that we can move on once its build is complete.

@aymather
Copy link
Copy Markdown

Just in case anybody is still listening to this topic...

You can also fix this issue by adding the -force flag to the hdiutil detach command.

I tested this with an application and it was still able to download and run on my computer without any noticeable issues. Again, here's how I propose fixing it.

Inside: lib/hdiutil.js

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)
    }
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants