Skip to main content

JRuby on Rails on Glassfish -- Unexplainable NameError

7 replies [Last post]
mwadhera
Offline
Joined: 2008-11-07

Hi, i'm trying to run a large rails app (12k+ LOC) under GF with the Glassfish v3 gem.

I start the app with: $ jruby -S glassfish_rails

The server starts without a hitch but as soon as I hit a controller I get a NameError:
NameError: uninitialized constant PointObserver

Now i'm sure this class is included in my environment's config.load_path -- in fact, starting a rails console session under jruby and typing PointObserver doesn't raise the exception, so i'm fairly sure this is isolated to my GF server. Furthermore, the app runs fine under JRuby WEBrick (jruby -S script/server webrick).

Here is a link to the stack trace: http://pastie.org/311820

My Setup:
$ jruby --version => jruby 1.1.4 (ruby 1.8.6 patchlevel 114) (2008-09-23 rev 6586) [i386-java]
$ glassfish --version => GlassFish gem version: 0.9.0
Rails 2.0.2 "frozen" to vendor/rails

Also, i'm seeing a bunch of warnings for reinitializing constants in my environment.rb file -- it appears as though the environment is being loaded more than once. I mention this as I think it might be related to the load error.

Any thoughts?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
crazeinc
Offline
Joined: 2004-12-07

Hi Vivek,

Could you send me (pjhyett@gmail.com) the updated jar as well, I'm running into the same issue.

Is the source not available somewhere we can track changes?

Thanks,
PJ

Message was edited by: crazeinc

Vivek Pandey

webtier@javadesktop.org wrote:
> Hi, i'm trying to run a large rails app (12k+ LOC) under GF with the Glassfish v3 gem.
>
> I start the app with: $ jruby -S glassfish_rails
>
> The server starts without a hitch but as soon as I hit a controller I get a NameError:
> NameError: uninitialized constant PointObserver
>
> Now i'm sure this class is included in my environment's config.load_path -- in fact, starting a rails console session under jruby and typing PointObserver doesn't raise the exception, so i'm fairly sure this is isolated to my GF server. Furthermore, the app runs fine under JRuby WEBrick (jruby -S script/server webrick).
>
> Here is a link to the stack trace: http://pastie.org/311820
>
> My Setup:
> $ jruby --version => jruby 1.1.4 (ruby 1.8.6 patchlevel 114) (2008-09-23 rev 6586) [i386-java]
> $ glassfish --version => GlassFish gem version: 0.9.0
> Rails 2.0.2 "frozen" to vendor/rails
>
> Also, i'm seeing a bunch of warnings for reinitializing constants in my environment.rb file -- it appears as though the environment is being loaded more than once. I mention this as I think it might be related to the load error.
>
>
Thanks for reporting. There is a bug in the glassfish gem's rails
adapter where it is parsing environment.rb twice. I just fixed this.
Although not sure this is what was causing the NameError. Any chance you
can provide a testcase. OR maybe I can send you the patched jar file for
you to try out?

BTW, I opened an issue[1] at http://rubyforge.org/projects/glassfishgem/.

-vivek.
[1]http://rubyforge.org/tracker/index.php?func=detail&aid=22741&group_id=5450&atid=21080

> Any thoughts?
> [Message sent by forum member 'mwadhera' (mwadhera)]
>
> http://forums.java.net/jive/thread.jspa?messageID=315905
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

mwadhera
Offline
Joined: 2008-11-07

It sounds like the NameError could be a symptom of the double-parse bug. Could you please send the jar to: mikewadhera at gmail -- I will try to reproduce. Thanks.

Vivek Pandey

webtier@javadesktop.org wrote:
> It sounds like the NameError could be a symptom of the double-parse bug. Could you please send the jar to: mikewadhera at gmail -- I will try to reproduce. Thanks.
> [Message sent by forum member 'mwadhera' (mwadhera)]
>
> http://forums.java.net/jive/thread.jspa?messageID=315930
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
Just sent you the jar to your gmail address. Let me know how it works
for you.

-vivek.

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

mwadhera
Offline
Joined: 2008-11-07

That jar fixed the re-init warnings for my environment.rb constants, the original NameError still persists.

I think the problem may be due to our code using custom load paths with non-namespaced constants.

For example, we have modules like Authentication that are in app/mixins/authentication.rb -- if I change the class name to Mixins::Authentication, GF seems to be able to load it. I realized this after I removed the observer class altogether -- there were more NameErrors, among them the one for the Authentication module. Subsequent NameErrors also popped up whenever I visited pages that reference models in subfolders (e.g. app/models/features/some_feature.rb) -- if I try to namespace these, I get a rails error saying the file didn't define the top-level constant rails expected...for example, if I change PointObserver to Observers::PointObserver, I get "Expected app/observers/point_observer.rb to define PointObserver".

This may not be the most scientific approach of isolating the issue but its really difficult to repro any other way (console & tests show no errors). Hopefully this will provide some direction for a resolution.

Vivek Pandey

webtier@javadesktop.org wrote:
> That jar fixed the re-init warnings for my environment.rb constants, the original NameError still persists.
>
> I think the problem may be due to our code using custom load paths with non-namespaced constants.
>
> For example, we have modules like Authentication that are in app/mixins/authentication.rb -- if I change the class name to Mixins::Authentication, GF seems to be able to load it. I realized this after I removed the observer class altogether -- there were more NameErrors, among them the one for the Authentication module. Subsequent NameErrors also popped up whenever I visited pages that reference models in subfolders (e.g. app/models/features/some_feature.rb) -- if I try to namespace these, I get a rails error saying the file didn't define the top-level constant rails expected...for example, if I change PointObserver to Observers::PointObserver, I get "Expected app/observers/point_observer.rb to define PointObserver".
>
>

This is good data. Can you provide how you are loading using custom load
path? Are you using $LOAD_PATH to load up your non-namespaced code?

-vivek.
> This may not be the most scientific approach of isolating the issue but its really difficult to repro any other way (console & tests show no errors). Hopefully this will provide some direction for a resolution.
> [Message sent by forum member 'mwadhera' (mwadhera)]
>
> http://forums.java.net/jive/thread.jspa?messageID=315945
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

mwadhera
Offline
Joined: 2008-11-07

The custom load path is setup by the Rails Initializer block in our environment.rb:
http://pastie.org/private/m3km2qcevup0dnnwacd0kq

We don't do any explicit requires e.g. all constants are pulled in by the implicit dynamic class loading baked into rails