socketry / async-http

MIT License
298 stars 45 forks source link

Stack level too deep (SystemStackError) then raise exception in Sync. Then try to show warn in console #156

Closed znppaed7 closed 2 months ago

znppaed7 commented 2 months ago

Example:

    def example
      Sync do
        response = @internet.get('https://example.com')
        raise 'exception'
        [response.success?, response.status, response.read]
      end
    end

Result: ruby-3.2.1/gems/activesupport-7.0.4.2/lib/active_support/core_ext/object/instance_variables.rb:15:in `map': stack level too deep (SystemStackError)

Problem code:

in file console/terminal/logger.rb

def format_options(options, output)
  format_value(options.to_json, output)
end

The data in the options field contains cyclic references. The to_json method is overridden in the active_support/core_ext/object/json.rb file.

class Object
  def as_json(options = nil) # :nodoc:
    if respond_to?(:to_hash)
      to_hash.as_json(options)
    else
      instance_values.as_json(options)
    end
  end
end

This method does not know how to resolve cyclic references. This problem exists only in the rails framework. There is no problem without rails framework.

I have no suggestion on how to solve this problem...

ioquatix commented 2 months ago

I believe this is a bug with Rails. Let me take a look.

ioquatix commented 2 months ago

I believe this can be fixed by the latest release of protocol-http.

Basically, Rails forced us to implement as_json.

ioquatix commented 2 months ago

There was a minor follow up: https://github.com/socketry/protocol-http/pull/54