I have set up a small Mojolicious app to run behind Plack acting as proxy like this:
builder {
mount "/q" => builder {
Plack::App::Proxy->new(remote => "http://127.0.0.1:3010")->to_app;
};
};
I need to run it this way (rather than mounting the application directly) as I need to reload the app a few times a day, for reasons I can't go into here.
The app runs on hypnotoad, and when I hit it directly, everything's fine. However, when hit via the plack proxy, I often get a 502 response - Gateway error: Connection timed out
.
The funny thing is, when I reload once or twice, everything seems fine, and I get the proper response.
Can anybody help figure this out?
It's more than possible that the default timeout values in Mojolicious aren't high enough for your app, which may lead to the worker process being stopped by the manager, resulting in an invalid response to the Plack app and thus the 502. So check the config settings for the timeouts and modify if necessary. You may also need to up the number of workers if your app is under heavy load, although i suspect that's not the problem here.
More useful information would be found in the mojolicious app log file - if you run hypnotoad under debug with MOJO_LOG_LEVEL=debug
then you will see the connection hit the app, and then a timeout if this is indeed the problem.
The response being fine on a reload is indicative of maybe something being slow to load in your app, or perhaps a cache being populated, etc. Hard to say without log entries from the hypnotoad server