Mongodb data corruption from heroku app cause & prevention - angularjs

I have a free heroku plan and a nodejs app on the heroku server. The nodejs app is built with meanjs, so the code for mongodb connections is exactly what you would find in the configuration files. I use a mongolab free mongo database to store the data. Occasionally (depending on how much I interact/change code I believe), the mongodb data is corrupted. I believe this to be true because I use a script to register names, and I can always log into them for awhile until I receive a no user/pass error. If I get this error and immediately create a new user, the user can successfully be logged in and out. All of the user data is still in the database. I also have a few other crud modules that use different collections in the same database, and I (so far) have not seen anything happen to that data, or anything to any of the data besides the password. I don't know where my error is possibly coming from, or what code is relevant, as I haven't touched the config files at all and to my knowledge haven't written any code that looks at user passwords at all. Also, my user object is occasionally empty (user = "") in the markup, but that bug was introduced after the original, I believe while I was trying to find out what was going on. Again, I don't have any clue though, so I included it just in case. Thanks!

After a lot of trial and error, I found the cause to my problem.
After I created these users, I go into my Mongolab account and manually edit the roles based on what module I'm working on (doing role based authentication). It is when editing the data that my passwords become corrupted. I don't know why, but I've pinpointed the problem to there. I've messed with some other data, with similar results.

Related

GAE Delete Domain Mapping not working

I have an old AppEngine project which is mapped to my domain. I recently transferred this domain to Google Domains.
I created a new AppEngine project which I now want to map to my domain instead of the old project. When I attempt to do so I get the error "my-domain-name is already mapped to a project." That makes sense.
However, when I attempt to delete the mapping from my old project (console.cloud.google.com/appengine/settings/domains?project=my-old-project-name) I get an error:
"Error
Sorry, there’s a problem. If you entered information, check it and try again. Otherwise, the problem might clear up on its own, so check back later.
Tracking Number: xxxxxxx
Send feedback
"
I've tried this several times so this is for sure not clearing up on its own. (I've also tried sending feedback but not gotten any reply)
Any idea on how I can move the mapping from my old AppEngine project to the new AppEngine project?

Cannot log in to Drupal site

I have a VM that I set up to do development on two sites hosted on Acquia with the same codebase. I'm using version Drupal 7.26. I have it where I can access both sites from the host computer, but when I try to log in using /user/login on either site, I get nothing. The POST returns a 404 containing the log in page again.
I've tried settings $cookie_domain = '.my-site.dev' as well as $cookie = 'www.mysite.dev'. Neither has any effect. I also tried adding a bunch of random charactersto the file to make sure I was editing the correct file; with the random characters, pages didn't load at all. (See https://www.drupal.org/node/611920#comment-3110010.)
I also tried doing repair table sessions. I forgot which site I saw that recommendation from. I also tried delete from sessions just for kicks. Neither worked.
Any ideas? Thanks!
edit: Per https://www.drupal.org/node/261411#comment-3182566, I tried to go to www.mysite.dev/?q=user/login. This did not give me a 404, but I had tried (unsuccessfully, it seems) to reset my password through the database. I'm at least getting an error about a bad username/password combination rather than nothing at all. Still, I would think /user/login should have worked, too.
edit 2: The production site uses CAS, but logging in through /user/login still works.

Laravel: Gracefully Fallback if Session Database is Not Avaiable

Is there a middware, package, or general approach for having Laravel gracefully fallback to a session-less state if the session storage engine isn't available?
That is, let's say you have you a system using the database session engine. If that database goes down, Laravel's going to throw an exception whenever it can't connect to the database. I'd like a way to, instead, have Laravel not throw an exception, and just continue on without a working session engine.
(I realize this will mean careful coding on the application level to never assume sessions are available, but a pre thank you for all the warnings)
Use Case to Correct For:
Session storage system goes down temporarily (maintenance window, unexpected outage, etc).
Logged in user hits a page, sees Laravel error page because session engine can't connect
User is sad
I'd rather the user see some sort of normal web-page instead of a generic error message, even if that means we can't include stateful session data on the page.
That depends, Laravel does not persistently require a session engine to work, only on pages that actually use it. So that means that a fallback would basically not help - in fact an exception is the best thing Laravel can actually do to help you here.
Why? Because an exception can be cought and, if that is what you want to do (even though it makes little to no sense), be ignored.
Maybe I'm understanding you wrong, what exactly do you want to fall back to?
For me it's really hard to imagine how could it work and what you need it for. For example when you need user to be logged to access some page what should happen if session db or whole db is down? For me the only solution is show the user info that something gone wrong because it will be hard to pretend that website is working if it's not. So application throw exception, you catch it and display error page for user (and send site admin e-mail or sms)
If you would try to pretend you probably make your users angry because they would try to log in and they wouldn't be logged in without any info, so they would try 2nd time, 3rd time and finally they would think that your site is broken and would never come back again. In my opinion it's better to tell them something is wrong and "hey, come back here in about 2 hours"

CakePHP - database sessions, ajax not saving

I am using sessions saved in the database. Works well. Lot of data relating to pagination, browsing history etc is stored perfectly within the database.
However, I notice that data sent to a controller using Ajax is not being stored successfully.
If I debug the session within the controller called by ajax, right after I have set the session vars, I see the values appear to be stored correctly in the session, but on subsequent requests, it transpires that the session vars have NOT been saved.
I have done some testing and have found that the problem disappears if I change back to using "php" for the session instead of "database".
I have eliminated pretty much everything from the mix - and it boils down to Cake not saving session data that is sent by ajax. Again, simply switching back to using "php" for sessions, and everything works perfectly.
I wonder if anyone has experienced anything similar?
CakePHP 2.4
Many thanks.
Well, in case anyone is interested, it turns out that the issue I was having was not strictly related to storing sessions in the database.
My application was making 2 ajax calls at the same time, both attempting to update the session. This was a bug / error on my part, and was causing other session-related issues too, such as returning 403 error status.
I removed the offending bug and all is now well.

log4net adonet appender

I am using adonet appender of log4net for database debugging. Logging level is set to error. Database logging is configured for two applications running on different servers writting to same table on Oracle database.The columns of table were loginId, level.The problems I am facing are:
Even the logging level is set to error, some info level statements were also shown in the table , and the corresponing level column is being shown as error.
In between some statements, Login Id is shown different than the actual user's login id who is running the application.
So, how to configure log4net on different servers to behave autonomously.
EDIT: I am facing these issues only when running multiple instances of an application otherwise log4net logging is fine.
Scenario: I browsed the published version of the application in 2 browsers with different login Ids and gone through different flow in each browser. The result was login id was getting jumbled. I am getting the login id value from User session in my code and then storing into log4net.GlobalContext.Properties.
After some research, I found that there were some alternatives for log4net.GlobalContext.Properties which can be found in http://logging.apache.org/log4net/release/manual/contexts.html. I think ThreadContext.Properties should be used instead of global.
I think that I am facing the issues because of storing into log4net.GlobalContext.Properties.
Issue 1: I checked the code, and the statements were logger.info. But in the database table it was logging with error level.
Issue 2: code for login Id:
user = (User)Session["User"];
log4net.GlobalContext.Properties["LOGINID"] = user.Login;
in web.config.
If you believe that ThreadContext.Properties can be used instead of global.properties can you show me how to use it for login_id.
I started to post this as a comment but I realized that while I don't have the details I need to give you a specific answer, I can point you in the right direction.
Issue 1: If you are getting statements in your database that are info statements but that are marked as error statements, this is a problem in your code. You have to tell log4net what level the log statement is. You can say that a "Hello World" statement is a FATAL error. It sounds like your program is sending messages you want marked as info messages to the log but they are marked as error statements. Look at where those statements are sent to the log file and you should see a log.ERROR statement. Change that to log.INFO and you should be good to go.
Issue 2: The login ID should show who executed the log statement. That means if you execute something under another account (for permissions) or if you use a service account, it will log that user instead of the person clicking the mouse. I can be much more specific in how to potentially fix this if you show us how you are logging the user information.
Issue 3: I'm not sure what you mean here. Log4net does behave autonomously. You can even use the same configuration on multiple servers without issue, if that is what you are alluding to.
If you would like a more complete answer that is more specific to your issues, please post the log4net config file and the relevant code (where you are logging the INFO statements and the method by which you log the user ID would be a good start).

Resources