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
» SeanTAllen (Sean T Allen): RT @diegosevilla: @SeanTAllen The uForth interpreter in #Erlang is here: https://t.co/75UcHlzoNw (feedback welcome!) /cc @jneira
» diegosevilla (Diego Sevilla Ruiz): @SeanTAllen The uForth interpreter in #Erlang is here: https://t.co/75UcHlzoNw (feedback welcome!) /cc @jneira
» diegosevilla (Diego Sevilla Ruiz): At last I’ve had the time to release it: uForth interpreted using model-driven techniques (#MDE) and #Erlang: https://t.co/75UcHlzoNw #EMF
» geeksays (A Geek): Erlang - A concurrent Programming Language [Overview] http://t.co/5xbhPXGKmn
» developerevents (USA Developer Events): Intro to Erlang for C# Developers - 20 May - 170 Graphics Drive, USA http://t.co/LCJ6ritUv8 #csharp #event
» vsovietov (vsovietov): RT @FrancescoC: Lots of companies in finance use Erlang, but they don’t want to speak about it in public. Morgan Stanley does: http://t.co/…
» nivertech (Zvi): RT @lhoguin: Cowboy Function Reference http://t.co/nA2x66QNPO the functions listed are part of the stable API that’s going into Cowboy 1.0 …
» nivertech (Zvi): RT @erlangfactory: #EUC2013: Early bird ends in 4 hours!
Last chance to get a discount ticket for the biggest #Erlang event in Europe http:…
» nivertech (Zvi): RT @FrancescoC: Lots of companies in finance use Erlang, but they don’t want to speak about it in public. Morgan Stanley does: http://t.co/…
» yunomu11 (Yusuke Nomura): RT @benymd_bot: @yunomu11 さんの特徴語。ビルド,ラブライブ,Haskell,Java,ライブラリ,パーサ,はてなブログ,コンパイル,モナド,面白い,バグ,プログラマ,TARI TARI,コード,サーバ,関数,AWS,Erlang,API,データ,クォー…
Statistics
Number of aggregated posts: 10648
Most recent article: May 14, 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…