Errno::EINVAL – Invalid argument
Windows' servers are pretty much an awful nightmare to get working. A company that I am doing work for had the bright idea of hosting a fairly major web application on windows. Not a good idea, not a good idea at all. This has caused nothing but problems from ferret to having no way of stopping a service to this error - Errno::EINVAL - Invalid argument.
The typical error you get looks something like this:
Errno::EINVAL in .....
Invalid argument
....
.../lib/active_record/base.rb:1358:in `write'
.../lib/active_record/base.rb:1358:in `compute_type'
....
Ya, that is not something you want to get and have no idea what is going on, not to mention that it only happens every once in a while. Especially, when you are already frustrated because nothing else seems to work perfectly.
The error is caused when you are using a windows server and have decided that, as a good windows' administrator, you will create a mongrel service for your application and set it to start automatically. The service knows nothing about STDOUT, so anything written to STDOUT will produce the error above. But, what still baffles me is the complete and utter randomness of the whole situation. Why does it not happen all the time, why only every 6 to 10 times that I hit the same exact page? Well, I can't help you there, but let me know if you have figured it out.
So, if you are lucky enough to get the same error above, then I have a solution for you, well actually a couple solutions. First, if you have the choice, ditch windows, not worth it. However, if you are like me and are forced to use windows for a project then your solution is a simple derivative of what you will find here.
None of those solutions worked for me, or at least not to the point where I was satisfied. They all got me very close, but without a way of still logging STDOUT. The closest and, as the link above points out, the safest was to redirect STDOUT to a logfile:
1 2 |
STDOUT.reopen(...)
|
Well, that, unfortunately, did not work for me for some reason, probably some fault of windows, I am sure. If you get it working, stick with that solution. Otherwise, I went with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
################################### # RAILS_ROOT/lib/std_out_logger ################################### class StdOutLogger def write(s) f = File.open("log/stdout.log", "w+") f.puts s.inspect f.close end end ################################### # RAILS_ROOT/app/controllers/application.rb ################################### # redirect the output to a log file for when we run as a service before_filter { $stdout = $stderr = StdOutLogger.new } |
I hope that helps you, it worked for me. Good luck.
5 Responses
to “Errno::EINVAL – Invalid argument”
Sorry, comments for this entry are closed at this time.
your post put me on the right track, thanks.
I am having same problem but when I try to load files…
Thanks
I think ed is really on to something here. It’s a satori.
Is this still a problem with the current version of mongrel_services? I am getting a bunch of these errors from out application but they are all related to the SOAP calls we are making and I’m trying to track down the real culprit.
Also, will logging these provide any information about the real problems or is this just a workaround to maintaining Mongrel stability?
Thanks!
And using before_filter and lib file I get the following error:
private method `print’ called for #
Rails 2.3.10
Ruby 1.8.6
Windows
Mongrel 1.1.5