{"record":{"id":"a7f25d459d9f3f4d","repo":"puppetlabs/puppet","slug":"pkg-could-not-install-name-after-tries-tries","errorCode":null,"errorMessage":"Pkg could not install %{name} after %{tries} tries. Aborting run","messagePattern":"Pkg could not install %(.+?) after %(.+?) tries\\. Aborting run","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/pkg.rb","lineNumber":247,"sourceCode":"    else\n      command = 'update'\n    end\n    args = ['--accept']\n    if Puppet::Util::Package.versioncmp(Puppet.runtime[:facter].value('os.release.full'), '11.2') >= 0\n      args.push('--sync-actuators-timeout', '900')\n    end\n    args.concat(join_options(@resource[:install_options])) if @resource[:install_options]\n    unless should.is_a? Symbol\n      name += \"@#{should}\"\n    end\n    unhold if properties[:mark] == :hold\n    begin\n      tries = 1\n      # pkg install exits with code 7 when the image is currently in use by another process and cannot be modified\n      r = exec_cmd(command(:pkg), command, *args, name)\n      while r[:exit] == 7\n        if tries > 4\n          raise Puppet::Error, _(\"Pkg could not install %{name} after %{tries} tries. Aborting run\") % { name: name, tries: tries }\n        end\n\n        sleep 2**tries\n        tries += 1\n        r = exec_cmd(command(:pkg), command, *args, name)\n      end\n    ensure\n      hold if @resource[:mark] == :hold\n    end\n    return r if nofail\n    raise Puppet::Error, _(\"Unable to update %{package}\") % { package: r[:out] } if r[:exit] != 0\n  end\n\n  # uninstall the package. The complication comes from the -r_ecursive flag which is no longer\n  # present in newer package version.\n  def uninstall\n    cmd = [:uninstall]\n    case (pkg :version).chomp","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/pkg.rb#L229-L265","documentation":"Raised in the install retry loop (lib/puppet/provider/package/pkg.rb:247) of the Solaris `pkg` provider. `pkg install` exits 7 when the IPS image is locked by another process; the provider retries up to 4 times with exponential backoff (2**tries seconds) and then raises Puppet::Error aborting the run.","triggerScenarios":"Concurrent pkg operations holding the image lock: a second puppet agent run, an in-progress `pkg update` / self-update, SMF refreshing image state, a GUI Package Manager session, or a hung pkg process.","commonSituations":"Overlapping cron schedules for puppet and OS updates; boot-time zone/image refresh still running; a stale pkg process wedged on the lock.","solutions":["Identify the lock holder: `ps -ef | grep pkg` and inspect active pkg/SMF processes; wait for or terminate the stale one.","Stagger schedules so puppet runs never overlap with unattended pkg updates.","Simply re-run the agent a minute later - the contention is usually transient.","If it recurs systematically, patch the retry budget (tries > 4 / sleep 2**tries) to fit your environment's lock hold times."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Skip the run while another pkg operation holds the image lock\npgrep -x pkg >/dev/null && { echo \"pkg busy - deferring puppet run\"; exit 0; }","typeGuard":null,"tryCatchPattern":"retries = 0\nbegin\n  provider.install\nrescue Puppet::Error => e\n  raise unless e.message =~ /after \\d+ tries/\n  retries += 1\n  retry if retries < 3\n  raise\nend","preventionTips":["Schedule puppet runs so they never overlap OS update jobs.","Exit early when a pkg process is already running (see validationCode).","Watch for wedged pkg processes at boot on zones/images and clear them."],"tags":["solaris","pkg","lock","concurrency","retry","exit-code-7"],"backgroundTag":"package-manager-lock-busy","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}