Empty responses with explorer after rails post - ruby-on-rails

Im facing a hairy bug when submitting a ruby on rails form on production environment, consisting on a blank response and page displayed by internet explorer 7-9.
This bug does not happen with any other common browsers and it's even quite random with ie as it sometimes works fine.
When failing, logs show a "200 OK in 0ms" which made me think about caching, but that didn't seem to be the source. After some debugging it looks like the server returns the 200 reply without even running the code; it doesn't stop on any breakpoint placed inside the action, tough logs show it was processed by it.
The failing form is a custom devise registration one, using devise in a spree 0.60 application and ruby on rails 3.0.7
Server is thin behind nginx.
Any suggestions? Thank you.

Related

Getting a white page when testing new gem/engine. Logs show views rendering, but the page is empty

I've been developing a gem/engine for a little bit, and using an existing app of mine to test it out. Everything has worked great. Then I went to add it to another app and suddenly it wasn't working. I figured it was because that app had some weird set up, but I've tried on a couple of other apps now and they all do the same thing.
When I go to visit the gem in the browser, the page is completely empty. It receives nothing from the server. No head, style, script, body. Just a blank page. I can visit other routes for these apps just fine and the pages load as expected. However, any of the routes added by the engine do this same load issue. The strangest part is: In my server logs, I see the correct controller hit, I see the views being rendered, I get the 200 OK at the end. I can do puts in the gem views and it will show up in the logs during the load process. There is absolutely no sign that anything went wrong anywhere, but yet... White page. I'm at a loss as where to even start debugging this. Does anybody have any experience with anything of the sort?
I created a new test app to verify and things worked as expected, but for some reason other existing apps have this issue.
Working apps:
Rails 5.0.2
ruby 2.7.2p137
Fresh/blank app: (Working)
Rails 6.1.4
ruby 2.7.2p137
Apps that don't work:
Rails 6.1.3.1
ruby 2.7.2p137
Rails 6.1.4
ruby 3.0.2p107
I'm not even sure where to start debugging this as there is no "error" so I'm at a bit of a loss.
The repo for the gem is here: https://github.com/Rockster160/command_proposal but I'm mostly looking for thoughts on how to work through why this issue is happening and out how to debug it.
Turns out this was caused because the app it was added in had links inside the layout. (Like a nav bar) I had a rescue block that caught those issues and attempted to look up the route in the main_app, however, that rescue still recognized that an error was thrown so rendered the empty file. It seems odd that would be the result, but I finally discovered that was the case.
To fix the routing issue, I had to include the main app routes as a helper in my main engine controller:
helper Rails.application.routes.url_helpers
However, this broke my engine routes, so I had to go through each of my engine's routes and explicitly call them off the engine.
tasks_path # Old way
command_proposal.tasks_path # New way

Ruby on Rails link generated with link_to helper no longer works in Chrome

Chrome has been making a lot of changes recently, and one of them has broken a code statement I use to retrieve a document stored in a database, related to a parent record. The action to upload the file and create the attachment relationship is working, so my users can still add documents. They can no longer download and view stored document attachments. The code is using the link_to helper method, and appears to be building the link correctly, verified by the fact that it still works using Edge, so my users have an ugly workaround, but I need to understand what is happening. I have confirmed that it is indeed Chrome that is the problem, because at first I couldn't recreate the defect in development (until I updated my Chrome browser to current version.) Now I can recreate the defect in my development environment.
When the link in my form is clicked, Chrome displays an error screen with this text:
This page isn't working
(*localhost*) sent an invalid response
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
If I extract the link using developer tools and try and execute it in an empty browser window, I get the same error.
The link is constructed like this:
(*name of the file attachment*)
Before you ask, yes, I have confirmed there are no commas or quotes in my file names! lol
I am hoping someone somewhere can point me to a solution, hopefully simple, maybe obvious, that I can use to get my web form to play nicely with Chrome again - application code change, web server configuration (I am running on RHEL7 Apache in production and Puma in development, my database is Oracle, and I am building with Ruby 2.3.6 and Rails 5.1.5, along with many many gems).
I hope I have covered all the relevant points. Thank you for taking the time to read this post!
Issue has been resolved by upgrading gem attach to version >= 1.0.5. Many thanks to the gem author for excellent responsiveness.

Rails server hanging even with even freshly created app

My rails server started hanging today, so I tried running different apps to see if the issue was caused by my app, even created an empty app and with that even the default page doesn't come up.
I've been using it as just an http server, testing front-end with adding files into the public folder, so, I don't even compile any actual ruby code, just plain HTML, CSS and JS.
When I try to browse localhost:3000, the page is unresponsive, I can't even view source and I'd like to add that this happens with Chrome, Safari, IE and Edge, so I don't think it's a caching issue on the browser front.
I tried running the server on a specific ip and port, also tried the 0.0.0.0 trick mentioned on some other questions, doesn't help me so far.
I'm using ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15] and Rails 4.2.5.
Any ideas?
Well, I ended up resolving the issue by uninstalling and reinstalling the whole stack. Couldn't find the reason behind the issue but if you get stuck with the same problem, apparently a complete reinstall fixes it...

Reverse Proxy with Heroku (for Wordpress) won't show full pages

I am trying to use a reverse proxy to serve a Wordpress blog running on EC2 at /blog from a rails app running on Heroku. I've used the rack-reverse-proxy gem and followed directions like this:
How can I use a subdirectory instead of a subdomain?
My app is running at http://myapp.com, my main target (wordpress) server is running at http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com.
The pages on the target server all serve up fine when accessed directly. However, no matter what page I try to get through the reverse proxy, the HTML gets cut off. I've tried serving via both my own custom builds of Wordpress on Ubuntu (EC2) and on hosted examples like Bluehost. I've tried to access simple, handmade HTML and text test files, as well as the php files automatically generated by wordpress. Every time, the file is cut off.
Text files just get randomly cut off after ~1000 characters (this is variable)
Ditto for hand-coded HTML files
Wordpress files seem to get cutoff during the <head> (often mid-word) and render an empty <body>.
If a page should exist (e.g. http://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/test-post, it will load (at least partially) at myapp.com/blog/test-post, so I don't know that rewrites are the issue.
I've tried enough variables on the wordpress/destination server that I'm inclined to think it's something on the Rails side (I have the same issue whether running "myapp" locally or on a Heroku test server). Beyond that, I'm stuck.
Any thoughts as to what I might be doing wrong? There's nothing in the Apache logs to indicate that anything is getting cut off. I'm pounding my head over this to no avail, and would really appreciate any help.
FIXED IT!
Digging into the rack-reverse-proxy gem, I found that I'm not the only person that had an issue with this:
Seeing some issues with Content-Length being corrupted, this ensures it matches body length as delivered.
The fix hasn't been merged into the master branch, but I forked my own copy, applied the fix, and it's working great. Hopefully it'll be merged into the master and nobody else will have to worry about this.
EDIT
One more thing that might be helpful for somebody else, if they are having problems with Visual Editing Mode not working under wordpress: Make sure that you also include this update to have the headers get passed in properly. The gem just hasn't really been updated in a couple of years, so it's up to you to go through and copy in fixes from other people. Applying those two fixes has everything working fine for me with a Heroku app/AWS&Ubuntu Wordpress setup.
Heroku will cut the request after a certain amount of time which would cause the behavior that you're seeing.
You basically have to pull the page from the wordpress blog and reserve it via Rack in the time for one request - think that could be the problem?

How can I prevent cache/cookies from affecting the path of ckeditor javascript files in a production rails app?

I have a built a rails app in which I am using the ckeditor 3.5.1 together with the ckeditor gem.
When running in development, everything works fine. But when I run in production, I get errors.Sometimes, the text_area with the ckeditor does not show up. But when I clear my cache and cookies, everything works fine. Then after a while, the error comes up again. The error comes up more often than not.
Closer investigation reveals that when the error occurs, some files like staging.domain.com/javascripts/ckeditor/config.js are instead being requested from staging.domain.com/posts/config.js which is naturally non-existent
(posts is from my Post model)
How can the cache/cookies affect which path the files are served from?
Does anyone know what else might be wrong and how I can fix it?
P.S. I am using Phusion passenger in production.
It would seem the problem was being cased by mod_pagespeed which was activated. By disabling it, everything came back to normal.
I am curious though, about how this was happening.

Resources