[scaldi-play 0.5.8] StackOverflow in Play 2.4 With Custom ErrorHandler

73 views
Skip to first unread message

Neil Chaudhuri

unread,
Sep 18, 2015, 11:12:24 PM9/18/15
to scaldi
I have a Play 2.4 application with a custom error handler with the following signature:

class MyErrorHandler(env: Environment, config: Configuration, sourceMapper: OptionalSourceMapper, router: () => Router, mailer: Mailer)
extends DefaultHttpErrorHandler(env, config, sourceMapper, new Provider[Router] {def get() = router()})


Note the Mailer as the last parameter in the constructor. I have bound Mailer and the custom handler like this:

bind[Mailer] when inProdMode to new ProdMailer
bind[Mailer] when inDevMode to new MockMailer
bind [HttpErrorHandler] to injected [MyErrorHandler] ('router -> injectProvider[Router])


The problem is I get a StackOverflowError on startup with this setup. If I remove the mailer from the methods where I use it but keep it in the constructor, the application starts just fine. Only when the mailer does something do I get the error.

Can anyone tell me where I messed up my bindings?

Thanks.


Neil Chaudhuri

unread,
Sep 18, 2015, 11:18:39 PM9/18/15
to scaldi
Actually check that. I just found another StackOverflowError on startup with the Mailer in the signature. So it seems to be intermittent--the worst kind of bug--with the Mailer in the parameter list but happens every time with the Mailer in the parameter list and used in a method..

Oleg Ilyenko

unread,
Sep 19, 2015, 10:54:34 AM9/19/15
to scaldi
Hi Neil,

I think it's similar kind of issue I also faced recently with `HttpRequestHandler` (https://groups.google.com/forum/#!topic/scaldi/4beiEok7D84). Making `mailer` a provider should solve this issue. Maybe you can try something like this:

class MyModule extends Module {
  // ...

  bind [HttpErrorHandler] to injected [MyErrorHandler] ('router -> injectProvider[Router], 'mailerProvider -> injectProvider[Mailer])
}

class MyErrorHandler(env: Environment, config: Configuration, sourceMapper: OptionalSourceMapper, router: () => Router, mailerProvider: () => Mailer)
    extends DefaultHttpErrorHandler(env, config, sourceMapper, new Provider[Router] {def get() = router()}) {
  lazy val mailer = mailerProvider()

  // ...
}

It's doesn't look very nice, but looks like it's necessary at the moment because of the way play wires all dependencies. I will investigating why it's the case for the `HttpErrorHandler` (as well as `HttpRequestHandler`)

Cheers,
Oleg

Neil Chaudhuri

unread,
Sep 19, 2015, 11:56:42 AM9/19/15
to scaldi
That seems to have worked. Thanks for the tip! Hopefully one day we can figure out what Play is doing to cause this issue.
Message has been deleted

Oleg Ilyenko

unread,
Sep 26, 2015, 12:50:30 PM9/26/15
to scaldi
FYI: looks like the module loading bugfix also resolved this issue, and allows to inject mailer without making it a provider: https://groups.google.com/d/msg/scaldi/SWSLOAWhazY/w1PTxrHFDgAJ (fixed in scaldi-play v0.5.9)
Reply all
Reply to author
Forward
0 new messages