Giter Site home page Giter Site logo

rack-freeze's Introduction

Hi there ๐Ÿ‘‹

My name is Samuel and I'm from New Zealand. I like cats, programming, and coffee. I am a Ruby core committer. Creator of Async & Falcon.

  • ๐Ÿ”ญ Iโ€™m working on improving Ruby's model for concurrency and building libraries to support highly scalable web applications.
  • ๐ŸŒฑ Iโ€™m learning about how to build a successful model for commercial open source.
  • ๐Ÿ‘ฏ Iโ€™m always excited to collaborate on anything concurrency related.
  • ๐Ÿค” I want to improve diversity in open source.
  • ๐Ÿ’ฌ Ask me about anything to do with Ruby or concurrency.
  • ๐Ÿ“ซ How to reach me: GitHub Discussions
  • ๐Ÿ˜„ Pronouns: he/him
  • ๐Ÿ“œ Indentation: tabs
  • โšก Fun fact: My cat likes to sit on my arms while I write code. At the time of writing she is 22 years old.

IMG_1169

New Zealand Open Source Awards

I am delighted to be part of the New Zealand Open Source community.

NZ-OSA-2021

rack-freeze's People

Contributors

ioquatix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rack-freeze's Issues

Freezes Only First Middleware Instance (or Application if No Middleware)

rack-freeze appears to freeze the rack application (set using Builder#run) if no middleware are used, or only the first middleware instance, as Builder#to_app returns the application itself or first middleware instance:

x = proc{}
Rack::Builder.new{run x}.to_app == x
# => true
Rack::Builder.new{use Rack::CommonLogger; run x}.to_app == x
# => false
Rack::Builder.new{use Rack::CommonLogger; run x}.to_app
# => #<Rack::CommonLogger:0x0008132b414510 @app=#<Proc:0x0008132b415a28@(irb):3>, @logger=nil>
Rack::Builder.new{use Rack::CommonLogger; use Rack::Lint; run x}.to_app
# => #<Rack::CommonLogger:0x00081317000460 @app=#<Rack::Lint:0x00081317000488 @app=#<Proc:0x000812e51f7a20@(irb):4>, @content_length=nil>, @logger=nil>

I'm guessing the intent is that rack-freeze should freeze all middleware instances used, not just the first one, and should either always freeze the rack application or never freeze the rack application for consistency. My vote would be always freeze the rack application, but that's more likely to break things.

I apologize if I'm off base here, I didn't actually try rack-freeze, just inspected the code and specs. If I'm wrong, it would probably be worth at least adding specs for the no middleware and multiple middleware cases.

Any advice on how to use this with Rails?

rack/rack#1149 (comment) hinted at the fact that Rails doesn't use Rack::Builder.

I've tried the steps in the readme, and am still able to run middleware that mutates state on each request.

Just wondering if you have any advice on how to run this (or something similar) on a Rails 4 (or 5 if that's easier, we are about to upgrade) app?

Tabs versus spaces

First, i love this library. You are amazing and this is great. I just had a conversation with someone the other day about writing something like this, and here it is already written!

Minor question/nit. I was looking through the internals, they're very clean. I was however wondering if we could switch from tabs to 2 spaces instead? It's not a requirement by any stretch, but 2 spaces seems to be the community norm and as you start getting contributions you'll likely end up with a miss-mash of tabs and spaces.

Would you accept a pull request that converted all the tabs to 2 spaces?

How to use this on rails application without error?

I tried to use this gem but I got error due to rails code lazying loading stuff:

The error

App 10285 stderr: [ 2017-04-03 14:04:33.2507 10319/0x007fec20701b60(Worker 1) utils.rb:87 ]: *** Exception RuntimeError in Rack application object (can't modify frozen #<Class:#<Spacious::Application:0x007fec26b13680>>) (process 10319, thread 0x007fec20701b60(Worker 1)):
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/railties-5.0.2/lib/rails/engine.rb:527:in `env_config'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/railties-5.0.2/lib/rails/application.rb:248:in `env_config'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/railties-5.0.2/lib/rails/engine.rb:693:in `build_request'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/railties-5.0.2/lib/rails/application.rb:521:in `build_request'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/railties-5.0.2/lib/rails/engine.rb:521:in `call'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/newrelic_rpm-4.0.0.332/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:160:in `accept_and_process_next_request'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 10285 stderr: 	from /users/pikachuexe/.rvm/gems/ruby-2.3.4/gems/passenger-5.1.2/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'

The rails source code

https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/engine.rb#L527

What should be done to get rid of the error?

Is it possible to use this gem with Newrelic?

When I try to set this up on an app that also uses Newrelic it produces stack overflow error:

Unable to load application: SystemStackError: stack level too deep
/app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:20:in `>=': stack level too deep (SystemStackError)
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:20:in `rack_version_supported?'
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:12:in `version_supported?'
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:32:in `middleware_instrumentation_enabled?'
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:94:in `use_with_newrelic'
from /app/vendor/bundle/ruby/2.4.0/gems/rack-freeze-1.2.0/lib/rack/freeze/builder.rb:28:in `use'
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:96:in `use_with_newrelic'
from /app/vendor/bundle/ruby/2.4.0/gems/rack-freeze-1.2.0/lib/rack/freeze/builder.rb:28:in `use'
from /app/vendor/bundle/ruby/2.4.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/rack.rb:96:in `use_with_newrelic'
 ... 9702 levels...
from /app/vendor/bundle/ruby/2.4.0/gems/puma-3.9.0/lib/puma/cli.rb:77:in `run'
from /app/vendor/bundle/ruby/2.4.0/gems/puma-3.9.0/bin/puma:10:in `<top (required)>'
from /app/vendor/bundle/ruby/2.4.0/bin/puma:22:in `load'
from /app/vendor/bundle/ruby/2.4.0/bin/puma:22:in `<main>'

From what I understand newrelic also wraps all middleware classes in its own class, which conflicts with rack-freeze:
https://github.com/newrelic/rpm/blob/master/lib/new_relic/agent/instrumentation/rack.rb#L142

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.