ruby-grape / ruby-grape/grape-entity

Frozen/Deadlocked Ruby thread instead of NoMethodError

Open
#357 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
729
Forks
154
PR merge metrics
No merged PRs in 30d

Description

I am not sure if this is a known issue or not, but when yielding to a block w/ 2 arguments (e.g. arity = 2) its possible to freeze your app / test code. The following coding mistake should have resulted in a NoMethodError. Instead, Ruby freezes and I have to kill -9 the thread.

The following will freeze my app in its tracks. It should throw a NoMethodError.

module Entities
  class Invoice < Grape::Entity
    expose :id
    expose(:foo) do |object, options|
      bar.to_s
    end
  end
end

The only mistake above was not referencing object first.

module Entities
  class Invoice < Grape::Entity
    expose :id
    expose(:foo) do |object, options|
      object.bar.to_s
    end
  end
end

I'm happy to try to fix this - but first I'm asking if anyone else has noticed this or maybe there is already a PR for something similar?

Versions

Ruby 2.7.3
Rails 6.1
grape (1.5.3)
grape-entity (0.9.0)

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.

Research direction

Start by reproducing the provided Grape::Entity Invoice example with the two-argument expose block and the missing object receiver. Trace the expose block's yield and error handling to identify why the mistake deadlocks instead of raising NoMethodError. Done means the example raises NoMethodError and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.