480 points · by todsacerdoti · 6y ago · 140 comments
I have written variants of "GIANT BUG... causing /usr to be deleted... so sorry...." into commit messages over the years. Such a classic part of history.
[1] Commit thread: https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commi...
[2] Issue thread (not as good): https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/issue...
EDIT: Github is timing out trying to load it. May want to use archive.org: https://web.archive.org/web/20130613012555/https://github.co...
At any rate, lots of people at Apple back then brand new to Unix, NeXT was still integrating, everything was still coming together. And they made one of the absolute most classic Unix newbie whoops moments: they wanted to clean up old versions of iTunes, so the used rm -rf... without quoting the path. It had this IIRC:
rm -rf $2Applications/iTunes.app 2
with $2 as the path. But of course classic Mac users were used to having spaces in drive names and folders and so on. If you only had the startup drive no problem. But if you'd partitioned or had an external drive and it had a space in the name, ie "Disk 1", then that'd become rm -rf Disk 1/Applications/iTunes.app 2 and you were off to the races. There were some fun discussion threads about it, although unfortunately the only Apple Discussions bookmarks I have saved from back then all seem to be dead. Not sure if they're still archived somewhere and the links just no longer redirect or it was cleared out sometime.They got that pulled real quick too, but I always secretly wondered if the genesis of Time Machine was somewhere around there... backups were pretty rough at that stage of the game. Well, everything about Mac OS X was pretty rough, though exciting too.
Edit 2: Did find an old /. discussion about it that still works. Bit of a blast from the past reading through some of those, both in what has changed and what hasn't:
https://apple.slashdot.org/story/01/11/04/0412209/itunes-20-...
The grandparent bug is as much a failing of the grandparent's script as the OS, which exposes itself as one global mutable namespace.
It didn't succeed because I wasn't 'root'. Maybe it was a local misconfiguration in this company. Not sure. But I've never looked at Go the same way again.
At least it's hilarious now, for some people it must've been horrifying.
1. Create the directory "C:\APPNAME-tmp"
2. Change the current directory to "C:\APPNAME-tmp"
3. Recursively delete everything under the current directory.
This worked fine for thousands of users until I came along -- running Windows 2000, with the "C:\" directory read-only for unprivileged users, running as an unprivileged user. At that point it became:
1. Try, and fail, to create the directory "C:\APPNAME-tmp"
2. Try, and fail, to change the current directory to "C:\APPNAME-tmp"
3. Recursively delete everything under the current directory, which is my home directory.
The authors were very apologetic when I pointed out the bug.
https://github.com/valvesoftware/steam-for-linux/issues/3671
Featuring probably the most unflappable human in the history of time as a bug reporter. One day I hope to have the fortitude this man does.
One of my professors used to say that he should be able to destroy your laptop, buy you an equivalent new one, and you should be up and running again within a few hours. Hard drives fail all the time and computers get lost/damaged/stolen. Losing your home directory on a computer should be expected, and definitely not the end of the world.
I've been using actual raid5 (via adaptec raid card) for years and very recently had one of my trusty 5TB HGST drives fail (after 3+ yrs of uptime).
Fortunately the rebuild worked, but there are so many horror stories of raid5 rebuilds NOT working it has me contemplating going back to simple mirroring.
You can say 'robust' but there are limits of what I think one can reasonably expect from a user. That they had backups at all is not necessarily the norm.
If you want to guard against rogue software (or clumsy fingers in the terminal), you'll probably need to have remote backups. It sounds like copies on the cloud saved this user, and it's not unrealistic to suggest users backup to the cloud (I think many already do with OneDrive/iCloud/Dropbox). If you're a Linux user who likes to tinker, you can set up a Raspberry Pi with a hard drive attached and use restic over SFTP (or any of the other numerous choices).
No one can delete the files afterwards, not even root, without removing the attribute first
It worked well with Mercurial, which is also append only. So I could commit as usually to my Mercurial repository, but it could not be deleted.
Ironically, I stopped doing that, because it messed my backups up. When running the backups as root, some tools would add the flag to the backuped files, but then later backups as non-root could not replace the file with new versions.
What do you use for that?
Secondly, treat all machines as cattle. No customization, unless done programmatically or repeated easily, and absolutely essential.
In practice, I have a tiny Dir in a Resilio share from which I bootstrap. It contains some cfg files/dies, a bashrc, passwords and share keys, some written notes for customizations that are not possible or unreliably so to automate. In my notes you will find for instance a package list for fresh installs, notes on which Firefox extensions to install, how to configure certain software that have only a GUI to reliably do so (and I test such instructions before I consider the tool ready for use), a zip of my thunderbird profile, and so on.
I started this way of thinking when my dad accidentally formatted my drive in 2000, and it has been bullet proof since. When I use new software, I do not consider it usable before I made a note or cfg backup in my 'bootstrap' share. I do not rely on my memory and I do not rely on a particular machine for anything, and it costs barely any effort other than being disciplined in never customizing a machine without recording and testing how to repeat that someday. If that is too much work? Then I will not use that software, apparently its not worth it.
[1] https://syncthing.net/ [2] https://restic.net/ [3] https://nixos.org/
rm -rf "$STEAMROOT/"*
Yes. I have bookmarked this issue as a reminder to always read every single shell script before execution. set -Eeuo pipefailAs for the other conclusion, I have a story of my own. I once shut down all of my company's asynchronous task processing for about 20 minutes, completely by mistake. Our web servers kept serving, and nobody external would have noticed a difference, but, for 20 minutes, our scrapers stopped scraping, our NLP classifiers stopped classifying, and a bunch of stuff that made us money wasn't happening. Had I not noticed it and fixed it ASAP, we probably would have lost money. Instead, I immediately announced what I had done, got help, and we fixed it.
The real moral of the story is that an honest mistake is nothing to be ashamed of. I make mistakes all the time. Some of them make it into production. Big deal. Everybody does.
This didn't happen on Windows, just in Wine. It also went away in the 1.10 patch IIRC, so whatever mysterious behavior resulted in that got fixed.
edit: Found it! [2] It was even more recent than I remembered.
[1] - https://forums.gentoo.org/viewtopic-p-2723361.html?sid=3c70a...
The records were orders. Millions of orders.
And it shipped actual, physical CDs across the world for free. It was 2004!
Then it shipped a free LTS that may not have been as stable as RHEL, but it was definitely fresher and with guaranteed updates (for main) for 5 years (3 on desktops early on). It was 2006.
“I shipped a hard disk formatting utility that doubled as a word processor.”
There's a reporting & data extraction language called Focus (nowadays WebFocus). I was working in a very old version, and had a few nested GOTO statements to form a loop where the final output was a customized email sent for each row of a query returned. I had to make a simple update, but accidentally deleted a line first. I reinserted it... one line off from where it had been. My careful GOTO structure went from a loop, to recursive. Instead of sending an email to each row returned, I sent an email to the first person. Then I sent an email to the second person and the first. Then to the third, and the second, and the first.
The list was about 1,000 recipients... but luckily it usually finished very quick, and I would monitor as it went, and noticed the long run time after about 100 iterations and killed it. I then checked the logs to see why it ran so long, and traced back my error and fixed it... and sent an apology email to the 100 recipients I accidentally spammed.
Pro-tip: turn-on the alerts after deploying the site.
I've been writing code for about as long as him, but because I started with Asm, which makes one become really careful with buffer sizes, doing something like making one thing larger would not be done without carefully looking "down the line" to see if any further changes were required; and they almost certainly were. That's not to say I haven't corrupted files before, but fortunately nothing quite as catastrophic as wiping the disk.
Might be some memory corruption caused by a wrong pointer in any other part besides the saving?
I don't think it's realistic to say that all incompetent engineers think they're competent.
Not entirely sure (and I have no intention of given Bethesda enough money to find out)
In '87 my first 256 computer had 640k of memory with a hd that was less than 1mb IIRC. It cost nearly 5 thousand dollars including the $700 dot matrix printer.
Let the good times roll!
Excuse me?! So if I'm writing a prng, should I write the numerical constants like
int modulus = 1 + (1+1+1)*(0 + (1+1+1)*(-1+... )...);What he is suggesting is that you generally not include literals in your code, and instead, use a constant/variable that can be traced back to a single place in order to make changes more visible and easier to deal with. That he makes exceptions for 1, 0, and -1 is explained by conventions in various languages where those values in context end up as generic and meaningful as any other language keyword and thus would not benefit from being referenced from a constant. That doesn't mean you wouldn't ever end up with constants that are 0, 1 or -1 though, just that you wouldn't assume every random place you might use those values (such as sorting algorithms) justifies a constant placeholder.
For further review on the topic, may as well start here: https://en.wikipedia.org/wiki/Magic_number_%28programming%29
I have some code where I needed to calculate what the 1st percentile of a list of numbers was. Since it doesn't make a lot of statistical sense to calculate a 1st percentile of fewer than 100 numbers, I inserted a condition like
if len(numbers) < 100:
# skip the calculation
and included a comment stating that 100 is explicitly not a magic number here. By that, I meant that you'll never want to change this 100, so, why bother obfuscating it behind a name?It's perfectly readable, if you understand why the calculation is skipped in the first place. If you don't understand why the calculation is skipped, giving it a name like TOO_FEW_NUMBERS_TO_CALCULATE_1ST_PERCENTILE isn't really going to give you much insight into why the calculation is skipped, anyway.
To me "if len(numbers) < MINIMUM_NUMBERS_FOR_1ST_PERCENTILE" still reads better and requires me not to need to refer to comments, which I fall back on when I do not immediately get the code.
So maybe the risk is not lowered, but readability is still improved.
(Oh, and I wonder what do you return for a list of all equal numbers when there are more than a 100? If it's that number, why would suddenly going from 100 to 99 change that? ;)
I'll admit, my example was overwrought with comedic intent, but I stand firm on this issue. Use a magic number twice? Yeah, go ahead and put that numeric literal somewhere convenient (but you still have a numeric literal) to the consumers of it and easy to find by your readers (not a top-level magic_numbers.h)
I'm a mathematician. The fear of numbers in code is an affront to the domain that I work in. YMMV. I put a lot of work into documenting my code, but for the love of pete, 2 is not a magic number: my example was no more overwrought than OP's rule.
In some cases, I'd say that 1 can be a magic number. For example, it would better to write
fprintf(STDOUT, output_string)
than fprintf(1, output_string)
However, 0 and ±1 have a special role in picking out the first/next/previous elements of a sequence (and related things), which is so common that it'd be silly to insist on defining POSSIBLE_NEXT_INDEX and POSSIBLE_PREDECESSOR. That said, people do seem to love Python's itertools, so....maybe that's where we're headed. I had somebody aggressively complain about the readability of the all-pairs for-loop, which I thought was basically standard. for(auto i=0; i<N-1; i++)
for(auto j=i+1; j<N; j++)
process(X[i], X[j])
The flip side is that I don't think you always need to do this. For example, this is silly: double triangle::area() const {
const double NORMALIZATION = 1/2.0;
return this->base * this->height * NORMALIZATION;
}
The point is just to make it clear why that particular number is being used and where it came from.Yes, of course if you have a formula that involves dividing by 2 or something you just include the number directly.
But anything that's a magic number, even if only used once, is better to have a named constant defined. The name of the constant becomes the documentation itself.
The other reason is that if someone needs to come in and maintain the code and change a magic number for whatever reason... if it's a defined constant, they know it should only need to be changed in that one place, assuming all magic numbers are defined in a sufficiently wide scope. If it's just a number, they have to search the whole codebose for all instances of that number, and investigate each and every one to see if it needs to be replaced as well or not.
/* From Park and Miller (1988, pg 1195), using their notation */
const int A = 16807;
const int M = 2147483647;
const int q = 127773;
const int r = 2836;
...
instead of "inlining" them into the code like
test = 16807 * (seed % 127773) - 2836 * (seed/127773)The "ban" on literals obviously exempts their definition. No one, outside a number theory textbook, is defining A as successor(successor(...(successor(1)))
That's pretty cool. Did you at least have to look it up?
I recommend the citation-in-the comments idea though. We do it for lab stuff and it's very helpful for everything from debugging to writing up results.
const int MAGIC_THING = 0xdeadbeef
& then say MAGIC_THING throughout the code, rather than using 0xdeadbeef in all your expressions
Also, you are referring to an orthogonal problem—you would presumably want to put magic constants into a static constant to reduce the chances of disagreement across references. Hell even if there’s a single usage I would expect magic constants to be clearly demarcated and documented.
Edit: didn’t see sibling constant, didn’t mean to dupe the reply itself. This certainly refers to in-line use of numeric literals vs those used in constant definitions.
If you want to go full spectrum the other way.