how to deal with the situation while DB Down? - ruby-on-rails

how to deal with the situation while DB Down!
Description:
Server:Passenger
Imagine:
While you app'running,one of the dbs down,so this rails goes wrong,when new request to the website,there will be new rails to answer the request(but DB still down),so it's keeping going wrong till all rails go wrong!
so whats the solution under this situation?

just update your /public/500.html
There are 404.html, 422.html, 500.html page in your public folder, whenever any error occurs depending on the error code one of there html is shown to the user.
You need to give same look and feel as your application with related message so that user should get acknowledge something bad is happens and at the same time should connected to the your application.

Related

MVC 4 [Authorize] is denying every user

I restarted my production webserver tonight because it was seeming slow. Since it has come back up, no users are able to get to any views with the [Authorize] attribute on them.
There has been absolutely no code changes since November. Not a single tweak or modification of any kind. I'm using the SqlMembership provider and I originally thought the issue was there with the login, but I can see that the call to MembershipProvider.ValidateUser() passes successfully (looked at a SQL trace as well as some logging). After login, I redirect the user to a view decorated with [Authorize] and get denied.
One thing to note that even makes this more strange is that if I register a new user (who gets logged in as part of the user creation process), they are able to get to [Authorize] pages just fine. But if they log out, they are unable to access the [Authorize] pages once they log back in.
I'm pulling my hair out on this one. My production site is down and literally the only thing I did was a simple server restart. I've searched around for hours and at this point have no clue what to even look into next.
If anybody has a some ideas I'd greatly appreciate them - I'm at a complete loss and have a ton of users impacted.
Well, a few windows updates later the issue fixed itself. My guess is there was an update applied but pending reboot that hosed everything up when I restarted. Then when it came back the system found a bunch more windows updates to apply. I ran through these and it fixed the problem upon the next reboot after these were applied.

Store Temporary Sensitive Data In Rails 4

I'm working on a Rails app but i'm having trouble implementing a solution for storing temporary data and automatically clearing it when the user sees it. I thought about using flash but that only works when the user visits via the next request. Im looking for something that will let the user browse the site and view other things but once they get to the page such as /example/, they see the temporary sensitive data, then next time they reload that page or go somewhere else and come back its permanently gone. Any suggestions?
Redis will be fastest and simplest solution (but not such simple as flash notices). Redis have built in lpop method to get something from list and remove it after that. I think you will not find good solution which will not require some setup (e.g. Redis installation)

BroadCast Admin message to Each Session User

I have a requirement to inform every user to save their work and logout so that admin can reset iis or do some changes in the asp.net MVC application server.
looping through session object collection is not thread safe that is what i have learned.
any other ideas?
and even if i can get hold of active sessions how do i send a message to those clients ?
thanks in advance.
Save the message in a database and query the database for every request to see if a message exist.
This seems like a poorly-defined requirement.
Serious maintenance should be done at a specific time, and users should be alerted to that time window well in advance.
Simply restarting IIS is a pretty quick procedure... is there any reason users would lose their work when simply restarting IIS? While I've been filling out this StackOverflow answer, for instance, they could have restarted the server a dozen times. Once I hit Post, if the server is down, it'll either timeout and leave my work in the textarea, or else it will connect successfully if the server is back in time.
If I'm not submitting data, but just clicking a link, the same applies: either the browser times out, in which case a simple refresh is enough once the server is back up, or it eventually takes the user where they want to go.
If you're doing pure AJAX requests you will need to handle a missing server yourself, rather than relying on the browser to do it, but you'd need to work that out anyway because of the Eight Fallacies of Distributed Computing #1: "The network is reliable." (see http://en.wikipedia.org/wiki/Fallacies_of_Distributed_Computing)
So, I'd actually push back on that requirement. They're asking you to do something that won't really meet the need (users don't lose data, have a reasonably good experience), that will become complicated, and that will be a brittle solution in the end.
Sounds like a case for SignalR!
https://github.com/SignalR/SignalR

Saving 500/404 errors in Ruby on Rails to a database?

Is there a way to save the 500/404 etc errors to your database so you can check them to see if there are any bugs on the site?
I thought you could send an JS AJAX request from the 500.html page. e.g.
/errors/create/?message=error_message&ip=123&browser=ie9
But I'm not sure how to get that information when running in production mode?
Any help greatly appreciated,
Alex
This is what I have in my application controller:
def rescue_action_in_public(exception)
#This is called every time a non-local error is thrown.
#Copy the error to the db for later analysis.
Error.create :exception_name => exception.exception.to_s, :backtrace_info => exception.backtrace.to_s
#Then handle the error as usual:
super
end
As you can see I have an Error model I created and this saves a new one to the DB whenever it happens. One thing to remember is that backtraces are much to big for string columns so you will need something bigger like a text type. This works in my Rails 3.0.5 app.
Logging errors to the db is inadvisable since these errors can often be caused by database issues. It's safer to append your errors to a file (on a separate disk) if your site is high traffic, if the file system is unresponsive, then your db won't work anyway. Even safer would be to use an asynchronous message queue hosted on another server. In both cases, you can create reports by periodically parsing your log output.

A public action method pagerror.gif / refresh.gif could not be found on controller - who is calling that gif?

Hello stackoverflow world.
(This is the first time I actually post a question here. Exciting)
A while ago I inherited a 2 year old MVC website from one of the teams within my corporation. I know most the ins and outs of this solution now but there is something strange cropping up in my error logs which I do not understand.
Every now and then I will get an error messages like this one:
A public action method 'xyz.gif' could not be found on controller MyNamespace.MyController
What I don't understand is WHY is this action (a gif image) being called in the first place?
I've seen 2 different gifs in the error logs pageerror.gif and refresh.gif
As this is an inherited solution I double checked everything and made sure that there are in fact no images like that in the project and no reference anywhere even to those words in the controllers, views, style-sheets or even in the source of pages within the same controller.
I seriously doubt that the users are playing around with the URLs and adding random gif names to them to see what happens.
I'm all out of ideas. Anyone out there who can suggest more places to look for the culprit?
Ta!
As Tchami pointed out in a comment on the original question, this is related to Internet Explorer's default error pages.
As I have set up custom error pages I believe this is either due to an internal server error or possibly somehow an action cancel error from the client side, i.e. client side error. I can't be 100% at this point.
The question is not fully answered but I mostly know what the cause is now.
From my point of view I've identified that I need to improve this ASP.NET MVC application so that
1) it doesn't report/log errors when someone tries to navigate to a non-existing controller action (e.g. these refresh.gif actions or any other)
and 2) handle it better for the client so that they don't end up clicking from one error page (default IE error page) to another (my custom error page when clicking the refresh icon on the IE page)
Another stackoverflow thread on a related topic:
Significance of 'pagerror.gif'?
(i can't post more links as I'm a new user)
CHEERS!
Solveig
Can you get the error to show up in the logs when you use the site yourself? If so, an add-in such as HttpWatch might help you see those .gif requests. If you can understand more about when they happen you might be able to figure out what's going on.
Pagerror.gif and refresh.gif are the default images from the IE browser/IIS server. Normally these images were shown when the browser is not able to retrieve the content.
If you see these errors in logs, then check the iis log to get more information.
For example,
IIS Log : look for this feild ,
cs(User-Agent)
compatible;+MSIE+6.0;+Windows
Here few things to be noted,
1)IE 6.0 apparently makes these requests on its own. I am not sure if any other IE 6+ Browser would show similar behavior.
2)All this will do is generates a 'bogus" event log entry because a null reference exception could happens when you request a non-existing GIF and that request goes through MVC pipeline.
3)Technically this simply can be ignored.
4) Optionally we could check if through routing we could stop “.gif” files from being processed by MVC Pipeline
All i would suggest is to handle it gracefully.
It may be difficult to pinpoint this, but my thought would be: check the javascript. If the image name is being dynamically generated somewhere, and then requested, a simple "find and replace" may miss the reference.

Resources