How to Crash Erlang
Programming in the 21st Century - James Hague - June 15, 2009Now that’s a loaded title, and I know some people will immediately see it as a personal slam on Erlang or ammunition for berating the language in various forums. I mean neither of these. Crashing a particular language, even so-called safe interpreted implementations, is not particularly challenging. Running out of memory or stack space are two easy options that work for most languages. There are pathological cases for regular expressions that may not truly crash, but result in such an extended period of unresponsiveness on large data sets that the difference is moot. In any language that allows directly linking to arbitrary operating system functions…well, that’s just too easy.
Erlang, offering more complex features than many languages, has some particularly interesting edge cases.
Run out of atoms. Atoms in Erlang are analogous to symbols in Lisp—that is, symbolic, non-string identifiers that make code more readable, like green or unknown_value—with one exception. Atoms in Erlang are not garbage collected. Once an atom has been created, it lives as long as the Erlang node is running. An easy way to crash the Erlang virtual machine is to loop from 1 to some large number, calling integer_to_list and then list_to_atom on the current loop index. The atom table will fill up with unused entries, eventually bringing the runtime system to halt.
Why is this is allowed? Because garbage collecting atoms would involve a pass over all data in all processes, something the garbage collector was specifically designed to avoid. And in practice, running out of atoms will only happen if you write code that’s generating new atoms on the fly.
Run out of processes. Or similarly, “run out of memory because you’ve spawned so many processes.” While the sequential core of Erlang leans toward being purely functional, the concurrent side is decidedly imperative. If you spawn a non-terminating, unlinked process, and manage to lose the process id for it, then it will just sit there, waiting forever. You’ve got a process leak.
Flood the mailbox for a process. This is something that most new Erlang programmers do sooner or later. One process sends messages to another process without waiting for a reply, and a missing or incorrect pattern in the receive statement causes the receiver to ignore all messages…so they keep piling up until the mailbox fills all available memory, and that’s that. Another reminder that concurrency in Erlang is imperative.
Create too many large binaries in a single process. Large—greater than 64 byte—binaries are allocated outside of the per-process heap and are reference counted. The catch is that the reference count indicates how many processes have access to the binary, not how many different pointers there are to it within a process. That makes the runtime system simpler, but it’s not bulletproof. When garbage collection occurs for a process, unreferenced binaries are deleted, but that’s only when garbage collection occurs. It’s possible to create a large process with a slowly growing heap, and create so much binary garbage that the system runs out of memory before garbage collection occurs. Unlikely, yes, but possible.
Categories: Blogs Programming in the 21st Century
Erlang on Twitter
» kirikaza (Kirikaza): RT @LogaRhythm: “If you don’t perform experiments before designing a new system, your entire new system will be an experiment” Mike William…
» digitalBush (Josh Bush): Lost a couple of hours figuring this one out “erl -pa ebin” needs to be “erl -pa ../{app}/ebin” if you want code:priv_dir/1 to work. #erlang
» buzzamzn (アマゾンに関する情報を発信中♪): 楽天市場:Learn You Some Erlang for Great Good!-【電子ブック版】 http://t.co/Ot4LPkbgw7 #amazon #アマゾン #相互フォロー
» rvalyi (Raphaël Valyi): @matrixise j’avais bidouillé un peu de Erlang récemment, pas trop mon truc, mais là avec la Syntaxe de Ruby/team Plataformatec, ça motive…
» imarshut (MarsHut): #Calling #Ruby #Functions http://t.co/79x1tBhoc9 ErlPort (library to connect Erlang to Ruby) 1.0.0alpha released
» fogelmania (Raphael Fogel): Alexander Fok, System Architect @ooVoo will have a talk at the #Erlang track of #DevconTLV http://t.co/GRA0Q2zny7 Welcone to TLV, Alexander!
» robertoaloi (Roberto Aloi): @mariofusco Wouldn’t it be simpler switching to #erlang? ;-)
» guillaumepotier (Guillaume POTIER): @francois2metz du coup tu vas recruter une armée de full stack ? Tu ne veux pas qques spécialistes Erlang ?
» oker1 (Zsolt Takács): Mochi Labs - statebox, an eventually consistent data model for Erlang (and Riak) http://t.co/tWhlCDGtBz
» HumphreyStamper (Humphrey Stamper): Wage reduction the trim erlang only http://t.co/6qTcEyl3Sk tactician in contemplation of organism leap http://t.co/1CWvIAjBNU
Statistics
Number of aggregated posts: 10658
Most recent article: June 13, 2013
Latest comments
» Moraru on This is Why You Spent All that Time Learning to Program: It is true that computer science was a pain in the back at time that i’ve had to learn it…
» Commercial hand dryers on Couchbase Meetup at new HQ: Buy online from here where you will get so much of variety in Commercial hand dryers for people. If you…
» Fort McMurray Homes on Motivated Reasoning and Erlang vs Python vs Node: I don’t really understand why this post is motivational? I don’t even see a post, just a title. Fort McMurray…