Possible Race Condition

Open
#19 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
ruby
Domain
backend

Research direction

Start with lib/execjs/external_runtime.rb lines 137-144 and the exec_runtime method shown in the issue. Reproduce or trace the reported error, then compare this implementation with the later gem version mentioned in the report. Done means establishing whether the exit-status check is racy and whether upgrading resolves the errors.

Written by the indexing model from the issue text.

Description

I'm looking at an error thrown in a Rails application which uses v2.0.2 of execjs. I think it may be due to a potential race condition in this method, but I want to

  1. validate my understanding of the error thrown
  2. check, if my understanding is correct and this has been repaired in a later version of the gem, whether a simple upgrade may resolve the errors

For completeness, the method body (which no longer exists in this manner on most recent version) is

def exec_runtime(filename)
  output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
  if $?.success?
    output
  else
    raise RuntimeError, output
  end
end

My understanding so far is that, if the most recent exit code is non-zero, the runtime will raise RuntimeError with the shell output even if the shell script executed successfully. The most recent exit code would not have been from the shell script supplying the output -- i.e. a race condition in examining $?

Thank you for your help.

Dominant language
Ruby
Stars
578
Forks
286
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rails/execjs

All issues in rails/execjs

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.