bowler-framework / Bowler

RESTful Web Framework based on Scala, built on top of Scalatra & Scalate
http://bowlerframework.org
BSD 3-Clause "New" or "Revised" License
119 stars 13 forks source link

IllegalArgumentException - setLastPath for first request #12

Closed thesmith closed 13 years ago

thesmith commented 13 years ago

Hey, I've been getting the following IllegalArgumentException:

java.lang.IllegalStateException
at org.eclipse.jetty.server.session.AbstractSessionManager$Session.setAttribute(AbstractSessionManager.java:1186)
at org.bowlerframework.http.BowlerHttpSession.setLastGetPath(BowlerHttpSession.scala:43)
at org.bowlerframework.view.scalate.ScalateViewRenderer.render(ScalateViewRenderer.scala:34)
at org.bowlerframework.view.scalate.BrowserViewRenderer$class.renderView(BrowserViewRenderer.scala:52)
at org.bowlerframework.view.scalate.ScalateViewRenderer.renderView(ScalateViewRenderer.scala:10)
at org.bowlerframework.view.Renderable$class.renderSeq(Renderable.scala:67)
at org.bowlerframework.view.Renderable$class.render(Renderable.scala:60)

This only happens on the first request for a user, so I assume it's complaining about there being nothing to set. For this, I'm using the FunctionNameConventionRoutes and jetty-7.4.1.v20110513.

Hope that's enough information!

thesmith commented 13 years ago

Oh, and I'm on trunk of bowler :p

wfaler commented 13 years ago

Without having run the code, I think I have an idea what the issue is (edge case I probably didn't think about when writing the code in question). I'll be back in the land of the reliably internet connected on Saturday, so a fix will hopefully be coming by Monday, hope that's not a problem.

wfaler commented 13 years ago

Somewhat struggling to replicate this even with the same jetty version..

What does the exact route look like and how does it look like when entered into the browser?

Any chance of a unit-test to replicate it? (ScalatraFunSuite should do the trick, POSORouteMapperTest has a few examples of use if it helps).

wfaler commented 13 years ago

Speculating here, but I was eventually able to reproduce the issue: In sbt 0.10, when using "jetty-run", first request seems to work fine.

However, if I do "~ jetty-run" for dynamic reloading of code changes, I will see the same failure that you describe on the first client request. Does this match your behavior, or can you reproduce the issue under other circumstances?

wfaler commented 13 years ago

Fixed (hopefully): https://github.com/wfaler/Bowler/commit/ab24b3ca39cf3f8a1e79ac3c9453ae1583cf9f5b

The servlet spec mentions that new sessions cannot be created if a response has already been committed. I would suspect that in some very rare edge cases on a first request, the "setLastGetPath" and "resetValidations" triggers this, as they are called after render within Bowler. The calls have now been moved above render so that the response is unequivocally not committed as far as the container is concerned.

wfaler commented 13 years ago

Available in master and 0.4.2-SNAPSHOT

thesmith commented 13 years ago

Sorry about the delay. Can't replicate the error now. Cheers for taking a look! :)