nulogy/vorpal

Code Reloading Broken

Closed this issue · 2 comments

Issue found with code reloading in the current version of Vorpal: 0.1.0.rc1. When I change my code and refresh my web page, an error is shown. When I refresh again, the error no longer shows, but my code reload does not work and my HTTP requests are serving responses from outdated code.

In my specific example, I have a Rails application running on a localhost server via Forego and using Vorpal objects. I change code in a Controller class that's serving up one of these objects via render json. I get the following error in my browser and my logfile:

NameError - wrong constant name Vorpal Generated ActiveRecord:
  activesupport (4.2.6) lib/active_support/core_ext/module/qualified_const.rb:30:in `block in qualified_const_defined?'
  activesupport (4.2.6) lib/active_support/core_ext/module/qualified_const.rb:29:in `qualified_const_defined?'
  activesupport (4.2.6) lib/active_support/dependencies.rb:376:in `qualified_const_defined?'
  activesupport (4.2.6) lib/active_support/dependencies.rb:610:in `autoloaded?'
  activesupport (4.2.6) lib/active_support/descendants_tracker.rb:24:in `block (2 levels) in clear'
  activesupport (4.2.6) lib/active_support/descendants_tracker.rb:24:in `block in clear'
  activesupport (4.2.6) lib/active_support/descendants_tracker.rb:20:in `clear'
  railties (4.2.6) lib/rails/application/finisher.rb:89:in `block (2 levels) in <module:Finisher>'
  activesupport (4.2.6) lib/active_support/file_update_checker.rb:75:in `execute'
  railties (4.2.6) lib/rails/application/finisher.rb:105:in `block (2 levels) in <module:Finisher>'
  activesupport (4.2.6) lib/active_support/callbacks.rb:446:in `block in make_lambda'
  activesupport (4.2.6) lib/active_support/callbacks.rb:192:in `block in simple'
  activesupport (4.2.6) lib/active_support/callbacks.rb:504:in `block in call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:504:in `call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
  activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_prepare_callbacks'
  activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:83:in `prepare!'
  actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:71:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  airbrake (5.4.0) lib/airbrake/rack/middleware.rb:22:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  web-console (3.3.0) lib/web_console/middleware.rb:131:in `call_app'
  web-console (3.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.3.0) lib/web_console/middleware.rb:18:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.6) lib/rails/engine.rb:518:in `call'
  railties (4.2.6) lib/rails/application.rb:165:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /Users/evanbrodie/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
  /Users/evanbrodie/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
  /Users/evanbrodie/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

I wonder if this log output from when we did our first successful load of this controller action has anything to do with this issue:

16:27:38 envlog.1    | Started GET "/users/current" for 127.0.0.1 at 2016-08-15 16:27:38 -0400
16:27:38 envlog.1    | Processing by UsersController#current as JSON
16:27:38 envlog.1    |   User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 3]]
16:27:38 envlog.1    |   Vorpal Generated ActiveRecord::Base Class for master_organizations. Object ID: 70320510386240 Load (1.9ms)  SELECT  "master_organizations".* FROM "master_organizations" WHERE "master_organizations"."id" = $1  ORDER BY "master_organizations"."id" ASC LIMIT 1  [["id", 2]]
16:27:38 envlog.1    | Completed 200 OK in 95ms (Views: 0.5ms | ActiveRecord: 5.2ms)

The issue continues to persist on Vorpal 0.1.0.rc1, when I do a code reload and then fire a request to my Vorpal-using Rails server. In addition to a similar backtrace as above, I am also printed out this code snippet that threw the error:

> wrong constant name Vorpal Generated ActiveRecord

activesupport (4.2.6) lib/active_support/core_ext/module/qualified_const.rb, line 30
------------------------------------------------------------------------------------

   25   class Module
   26     def qualified_const_defined?(path, search_parents=true)
   27       QualifiedConstUtils.raise_if_absolute(path)
   28   
   29       QualifiedConstUtils.names(path).inject(self) do |mod, name|
>  30         return unless mod.const_defined?(name, search_parents)
   31         mod.const_get(name)
   32       end
   33       return true
   34     end
   35