Why HN was down
1049 pointsOn a comment thread, a new user had posted some replies as siblings
instead of children. I posted a comment explaining how HN worked.
But then I decided to just fix it for him by doing some surgery in
the repl. Unfortunately I used the wrong id for one of the comments
and created a loop in the comment tree; I caused an item to be its
own grandchild. After which, when anyone tried to view the thread,
the server would try to generate an infinitely long page. The
story in question was on the frontpage, so this happened a lot.
For some reason I didn't check the comments after the surgery to
see if they were in the right place. I must have been distracted
by something. So I didn't notice anything was wrong till a bit
later when the server seemed to be swamped.
When I tailed the logs to see what was going on, the pattern looked
a lot like what happens when HN runs short of memory and starts
GCing too much. Whether it was that or something else, such problems
can usually be fixed by restarting HN. So that's what I did. But
first, since I had been writing code that day, I pushed the latest
version to the server. As long as I was going to have to restart
HN, I might as well get a fresh version.
After I restarted HN, the problem was still there. So I guessed
the problem must be due to something in the code I'd written that
day, and tried reverting to the previous version, and restarting the
server again. But the problem was still there. Then we (because
by this point I'd managed to get hold of Nick Sivo, YC's hacker in
residence) tried reverting to the version of HN that was on the old
server, and that didn't work either. We knew that code had worked
fine, so we figured the problem must be with the new server. So
we tried to switch back to the old server. I don't know if Nick
succeeded, because in the middle of this I gave up and went to bed.
When I woke up this morning, Rtm had HN running on the new server.
The bad thread was still there, but it had been pushed off the
frontpage by newer stuff. So HN as a whole wasn't dying, but there
were still signs something was amiss, e.g. that /threads?id=pg
didn't work, because of the comment I made on the thread with the
loop in it.
Eventually Rtm noticed that the problem seemed to be related to a
certain item id. When I looked at the item on disk I realized what
must have happened.
So I did some more surgery in the repl, this time more carefully,
and everything seems fine now.
Sorry about that.
Comments (287) 94 threads
Show all comments
Showing thread 2 of 94
I am reminded of an long-in-the-tooth sysadmin of my acquaintance who logged in everywhere as root. His theory - "they are my boxes. I screw it up, I fix it." I eventually realised that typing sudo every time he touched a box was no defence against doing the wrong thing.
An awful lot of sites at 1.2m views would have outsourced the running and development of the whole thing - there are entreprenuers who say its not even worth our time to code up the MVP. I find this approach sensible from a business point of view, but still it does not sit right with me.
I am supposed to have a nice website with lots of good content to attract inbound marketing - so I tried getting someone on textbroker to write an article for me. It read like a High School essay - no life, no anime. And so I will probably write my own CMS and my own content.
And pg sits there and writes his site in his own language, with his own moderation tools. Apart from the hilarious idea he could find a ten person ruby shop to outsource to, its nice to see someone taking the time to play again. Its why I like to see jgc on here too.
I am not entirely sure those thoughts are joined up (I am procrasting like crazy) but if they come to mean anything its we are playing in pg's sandbox. If the sand leaks it's his sand, and the only company this is mission critical to is YC.
Your procrasting like crazy has much anime.
IIRC, sudo logs all commands to syslog. Which might come in handy. Yes, root commands will be logged by bash to .bash_history, but there are limits of # of commands lots, what happens if you are logged in multiple times into same account etc.
Anyway, that's why I like sudo.
At work, a relatively young engineer accidentally typed a command meant for a test database server into a production window. There was a big rush to restore from backups, and there was a small amount of data loss.
One thing that came out of the retrospective, requested by the engineer in question, was the production hat. Before you opened up a connection to a production machine, you had to put on the large pirate hat. You could only put it back when you had closed the connections. I didn't really need it, but it was a great way for people to learn the necessary caution.
It also ended up being a nice exclusive lock on futzing with production, and seeing it in use led to some good discussions that otherwise might not have happened. But the main thing was developing a strong differentiation of states in everybody's heads.
My son now definitely thinks work is like his school :-)
Sure I could do it in 10 seconds and save myself 290 seconds (a 97% savings!) but then one day I'd have to scramble like crazy in the middle of the night trying to figure out what I screwed up for hours on end.
I'm not saying don't build an admin tool, obviously those are needed for things like banning users, but just get in there and carefully fix the data if something is wrong.
1. Always, always make a backup just before the hack.
2. Write a small set queries like 3pt14159's to check uniqueness and other pertinent properties.
3. Write a SELECT query to show the data you are going to change.
4. Borrow the WHERE clause from 3, and write your UPDATE statement.
5. Run 4, and then run 3 again to see that you successfully fixed it.
6. When it goes wrong, restore the backup from 1 :0
I still sometimes get that sinking feeling in the stomach that I have screwed something up, usually just after I hit the 'execute' button. And I really don't want to have to take the site down to run the restoration.
I thought everyone did this - well... for small datasets, skip the back, use a transaction. Rollback if your step 5 failed and try again.
Otherwise, I end up having this conversation (which actually happened):
Him: is having troubles! Features X, Y, and Z aren't working! Me: Hmm, has anything changed? It was all OK on Friday. Him: No, nothing's changed. Me: Really? Him: Well I ran a bunch of scripts on Saturday while I was visiting them. Me: OK, so what exactly did you run? Him: Just a bunch of scripts.
I learnt this after I inherited a project which had been written by some Romanians and it was pretty horrible. There was no MVC framework, it was a hacked together mess.
Somehow the live site started using the staging database instead of the production database, both were on the same server. Every time we (the devs) pushed to staging a script would grab the latest version of the live database and overwrite (drop tables) the staging database. The assumption being that the staging database is a bit like a demo server, changes made to it are temporary and just for testing, but that it should look as similar to the main website (but updated) as possible. The production database was backed up in about 5 different ways, but the staging database wasn't backed up at all.
After about a week of vanishing books, books which authors had uploaded to the self publishing portable with descriptions and other information, we realised what was wrong. Their files stayed but their accounts and book details were wiped.
In another epic fail on the same server I later moved the root folders by running the following as root (I'd probably have been stupid and run the same command if not as root but I'd have put sudo in front of it). > cd /home//public_html/public_html > mv /* ../
I was meant to mv ./* (files from the current directory into one below cause they'd been copied across into the wrong folder. Needless to say moving the root folders such as /etc and especially /lib and /bin is a BAD idea. Although is fixable, but that's another story.
Even if you can't replicate the entire live db, if you can automate backup, deployment of changes and test first elsewhere it makes the entire process far less fraught.
I hack on the "live" DB every day, and by live I mean i sync this DB to another environment, try it out, run it on prod.
UPDATE line_items SET quantity = 1 WHERE quantity < 1;
I'd script the following updates:
UPDATE line_items SET quantity = 1 WHERE quantity < 1 AND id = 123;
For each of the individual rows that needed to be changed. Then I have a check that I'm really updating just the rows I expect, this is especially important to me where the UPDATE involves joins, as I find this is the trickiest to get right.
(Not so much Jung's inner woman)
I think the sentence does read better if it is complaining there are not enough cyberpunk Japanese comics on my site though :-)