Passenger + Apache + Rails + DatabasedotCom 'Exception type: Passenger::SecurityException Error message: Line too long'

790 views
Skip to first unread message

Jimmie Butler

unread,
Oct 22, 2013, 2:01:22 PM10/22/13
to phusion-...@googlegroups.com
I get the following error with a setup including Passenger, Apache, Rails and Databasedotcom.

An internal error occurred while trying to spawn the application.
Exception type: Passenger::SecurityException
Error message: Line too long
Backtrace:
     
in 'std::string Passenger::ApplicationPool2::Spawner::readMessageLine(Details&) [with Details = Passenger::ApplicationPool2::SmartSpawner::StartupDetails; std::string = std::basic_string<char>]' (Spawner.h:718)
     
in 'std::string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:558)
     
in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
     
in 'virtual Passenger::ApplicationPool2::ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744)
     
in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned int)' (Implementation.cpp:782)


When looking at apache's error logs.

[ 2013-10-22 11:47:40.0484 26380/7fb124a58700 Pool2/Spawner.h:738 ]: [App 26425 stdout] ***** REQUEST: https://na12.salesforce.com/services/data/v22.0/sobjects/Account/describe
[ 2013-10-22 11:47:40.4836 26380/7fb124a58700 Pool2/Implementation.cpp:849 ]: Could not spawn process for group /var/www/invoices-rails/current#default: Line too long
     
in 'std::string Passenger::ApplicationPool2::Spawner::readMessageLine(Details&) [with Details = Passenger::ApplicationPool2::SmartSpawner::StartupDetails; std::string = std::basic_string<char>]' (Spawner.h:718)
     
in 'std::string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:558)
     
in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
     
in 'virtual Passenger::ApplicationPool2::ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:744)
     
in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned int)' (Implementation.cpp:782)




Which seems to indicate that the response, or the request for the Account describe is a 'Line too long'.

The response from salesforce on my development machine comes to 41858 characters with spaces and no newlines. 

Searching passenger's code for the error, I only found two places in which it occurs ( likely called from a variety of places in the code).

static pair<unsigned int, bool> newlineFound(const char *data,
               
unsigned int size, string *output, unsigned int max)
       
{
               
const char *newline = (const char *) memchr(data, '\n', size);
               
if (newline != NULL) {
                       
unsigned int accepted = newline - data + 1;
                       
if (output->size() + accepted > max) {
                               
throw SecurityException("Line too long");
                       
}
                        output
->append(data, accepted);
                       
return make_pair(accepted, true);
               
} else {
                       
if (output->size() + size > max) {
                               
throw SecurityException("Line too long");
                       
}
                        output
->append(data, size);
                       
return make_pair(size, false);
               
}
       
}


string readLine(unsigned int max = 1024, unsigned long long *timeout = NULL) {
               
string output;
                readUntil
(boost::bind(newlineFound, _1, _2, &output, max), timeout);
               
return output;
       
}

This seems to indicate that passenger thinks no line should be over 1024 characters.

What would anyone suggest I do to get around this?  I'm open to any setup changes or options which could work. Do I need to recompile passenger with a higher limit? Serve pages without Apache/Passenger?  The app works on heroku.



Hongli Lai

unread,
Oct 22, 2013, 2:12:24 PM10/22/13
to phusion-passenger
When spawning your application, Phusion Passenger sends some messages
to the app process, and the app process sends some messages back. This
communication happens through the app's stdin and stdout channels. The
SecurityException here indicates that one of those messages are too
long.

One possible reason why this happens, is when your shell startup files
(e.g. bashrc) print very long lines, longer than 1024. Because as
described at https://github.com/phusion/passenger/wiki/Debugging-application-startup-problems,
Passenger spawns applications through 'bash -l -c'. If this is the
cause of your problem then there are two solutions:
1. Use `PassengerLoadShellEnvvars off` (Apache) or
`passenger_load_shell_envvars off` (Nginx) to disable spawning through
bash.
2. Modify your bashrc and other shell startup files, and prevent them
from printing long lines.

It could also be that, during startup, your application prints very
long messages without newline. If that is the case then you can either
modify your app not to do that, or you can change the default limit in
BufferedIO.h and recompile.
> --
> You received this message because you are subscribed to the Google Groups
> "Phusion Passenger Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to phusion-passen...@googlegroups.com.
> To post to this group, send email to phusion-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/phusion-passenger.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Phusion | Ruby & Rails deployment, scaling and tuning solutions

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Jimmie Butler

unread,
Oct 27, 2013, 10:26:54 AM10/27/13
to phusion-...@googlegroups.com
Thanks for the help, from all I can tell what you've said seems accurate.  We ended up playing with the databasedot com gem configuration and found that changing from the generic login server to instead specify the server that we would get redirected to the problem fixed itself.

Максим Духанов

unread,
Dec 24, 2015, 2:19:02 AM12/24/15
to phusion-...@googlegroups.com
I have the same problem. But I do not understand the point 2. Explain what to do. How you want to edit bashrc?

вторник, 22 октября 2013 г., 21:12:24 UTC+3 пользователь Hongli Lai написал:

Daniel Knoppel

unread,
Dec 24, 2015, 6:43:04 AM12/24/15
to Phusion Passenger Discussions
On Thursday, December 24, 2015 at 8:19:02 AM UTC+1, Максим Духанов wrote:
I have the same problem. But I do not understand the point 2. Explain what to do. How you want to edit bashrc?

You only have to modify scripts that print long lines. So if there's a long line printed by something in bashrc, change that to not print..

- Daniel

Loïc

unread,
Apr 14, 2016, 11:19:03 AM4/14/16
to Phusion Passenger Discussions
You saved my day. I struggled to find this one.
My app prints out a very long message at startup without any new line and that was the culprit.
Thanks a lot for the clear explanation.
Loïc
Reply all
Reply to author
Forward
0 new messages