SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
Bugs
From Outer Space
While42 — SF chapter — #6
Why this talk?
Codito, ergo erro
I code, therefore I make mistakes
Outline
I'll show some really nasty bugs,
tell stories of unglorious battles.
(Some of which I've actually fought!)
Featuring: Node.js, EC2, LXC, pseudo-
terminals
and also: hardware bugs, dangerous bugs...
Our files,
Node.js is truncating
them!
It all starts with an angry customer.
“Sometimes, downloading this 700 KB JSON
file will fail, because it’s truncated!”
But… Do you even Content-Length?
(The client library should scream, but it
doesn’t.)
Gotta Sniff Some Packets
Log into the load balancer (running Hipache)...
# ngrep -tipd any -Wbyline '/api/v1/download-all-the-things' tcp port 80
interface: any
filter: (ip or ip6) and ( tcp port 80 )
match: /api/v1/download-all-the-things
####
T 2013/08/22 04:11:27.848663 23.20.88.251:55983 -> 10.116.195.150:80 [AP]
GET /api/v1/download-all-the-things.json HTTP/1.0.
Host: angrystartup.com
X-Forwarded-Port: 443.
X-Forwarded-For: ::ffff:24.13.146.16.
X-Forwarded-Proto: https.
...
Ngrep Doesn’t Cut It.
FETCH THE
WIRESHARKS!
# tcpdump -peni any -s0 -wdump tcp port 80
(Wait a bit)
^C
Transfer dump file
DEMO TIME!
What did we find out?
Truncated files happen because a chunk
(probably exactly one) gets dropped.
Impossible to reproduce locally.
Only the customer sees the problem.
THE PLOT THICKENS.
GET YOUR SWIMSUITS,
WE’RE DIVING INTO CODE!
This is Node.js.I have no idea
what I’m doing.
Add console.log() statements in Hipache.
Add console.log() statements in node-http-
proxy.
Add console.log() statements in node/lib/http.js.
The latter didn’t work.
“Fix”: replace require(‘http’) with require(‘_http’)
and add our own _http.js to our node_modules.
Do the same to net.js (in “our” _http.js).
It’s all in the pauses
Backend sends lots of data to Hipache.
Hipache sends data to client, but client is slow.
Hipache “pauses” the backend stream.
(i.e. stops reading from the network socket.)
When the client has read enough data,
Hipache “resumes” the stream.
etc.
SO FAR, SO GOOD
It’s all in the awkward
……………………...pauses
There are two layers in Node: tcp and http.
When the tcp layer reads the last chunk,
the socket is closed by the backend.
The tcp layer notices, and sends an “end”
event.
The “end” event causes the “http” layer to finish
what it was doing, without sending a
“resume”.
As a result, some chunks remain in the buffers
How do we fix this?
Pester Node.js folks
Catch that “end” event, and when it happens,
send a “resume” to the stream to drain it.
(Implementation detail: you only have the http
socket, and you need to listen for an event on
the tcp socket, so you need to do slightly dirty
things with the http socket. But eh, it works!)
What did we learn?
When you can’t reproduce a bug at will, record
it in action (tcpdump) and dissect it
(wireshark).
Spraying code with print statements helps.
(But it’s better to use the logging framework!)
You don’t have to know Node.js to fix Node.js!
Hardware has bugs, too
Pentium FDIV bug (1994):
errors at 4th decimal place
Pentium F00F bug (1997):
using the wrong instruction hangs the machine
ATA transfer speeds vary when you touch
ribbon cables (SATA introduced in 2003)
A story of Go, PTYs, LXC:
It never works the first time
# docker run -t -i ubuntu echo hello world
2013/08/06 23:20:53 Error: Error starting container 06d642aae1a:
fork/exec /usr/bin/lxc-start: operation not permitted
# docker run -t -i ubuntu echo hello world
hello world
# docker run -t -i ubuntu echo hello world
hello world
# docker run -t -i ubuntu echo hello world
hello world
# docker run -t -i ubuntu echo hello world
hello world
Strace to the rescue!
Steps:
1. Boot the machine.
2. Find pid of process to analyze.
(ps|grep, pidof docker...)
3. “strace -o log -f -p $PID”
4. “docker run -t -i run ubuntu echo hello world”
5. Ctrl-C the strace process.
6. Repeat steps 3-4-5, using a different log file.
Let’s compare the log files
Thousands and thousands of lines.
Look for the error message.
(e.g. “operation not permitted”)
Other approach: start from the end, and try to
find the point when things started to diverge.
That’s why we have dual 30” monitors.
Investigation results
First time
[pid 1331] setsid() = 1331
[pid 1331] dup2(10, 0) = 0
[pid 1331] dup2(10, 1) = 1
[pid 1331] dup2(10, 2) = 2[pid 1331] ioctl(0,
TIOCSCTTY) = -1 EPERM (Operation not permitted)[pid 1331]
write(12, "10000000", 8) = 8
[pid 1331] _exit(253) = ?
Second time (and every following attempt)
[pid 1414] setsid() = 1414
[pid 1414] dup2(14, 0) = 0
[pid 1414] dup2(14, 1) = 1
[pid 1414] dup2(14, 2) = 2[pid 1414] ioctl(0,
TIOCSCTTY) = 0[pid 1414] execve("/usr/bin/lxc-start", ["lxc-
start", "-n", ...]) <...>
What does that mean?
For some reason, some part of the code wants
file descriptor 0 (that’s stdin) to be a terminal.
The first time we run, it fails, but in the process,
we acquire a terminal.
(UNIX 101: when you don’t have a controlling terminal and open a file
which is a terminal, it becomes your controlling terminal, unless you
open the file with flag O_NOCTTY)
Next attempts are therefore successful.
… Really?
To confirm that this is indeed the bug:
● start the process with “setsid”
(which detaches from the controlling
terminal)
and see that the bug is back;
● check the output of “ps” (it shows controlling
terminals) and see that indeed, before the
first execution, we didn’t have a controlling
terminal, and we have one after!
How to fix the bug?
¯_(ツ)_/¯
I don’t know — yet!
(The bug was diagnosed last week,
and honestly, it’s not a showstopper.)
What did we learn?
strace is awesome to analyze behavior of
running processes.
ltrace can be used, too, if you want to
analyze library calls rather than system calls.
If you’re really desperate, gdb is your friend.
(A very peculiar friend, but a friend
nonetheless.)
“Errare humanum est,
perseverare autem
diabolicum”
“To err is human,
but to really foul things up,
you need a computer”
Really nasty (and sad)
bug:
The Therac-25
Radiotherapy machine (shoots beams to cure cancer)
Two modes: low energy and high energy.
In high energy mode, a special filter is inserted.
In other versions, a hardware system prevented
the high energy beam from shooting if the
filter was not in place.
On the Therac-25, it’s in software.
Konami Code of Death
On the keyboard, press (in less than 8
seconds)
X ↑ E [ENTER] B
...And the high energy beam shoots, unfiltered!
6 accidents, 3 died. (This was 1985-1987.)
Explanation: race condition in the software.
Never happened during tests since this was
Aggravating details
Many engineering and institutional issues.(No
software review, no evaluation of possible failures,
undocumented error codes, no sensor feedback…)
After entering the sequence and sending one
beam, the machine would display an error.
But errors happened “all the time” (usually
without adverse effect) so the operator would
just proceed (equivalent of pressing “retry”).
Let’s get back to weird
Linux Kernel bugs
Random crashes on EC2
Pool of ~50 identical instances, with same role.
Sometimes, one of them would crash.
Total crash: no SSH, no ping, no log, no
nothing.
EC2 console won’t show anything.
REPRODUCE THE BUG?
IMPOSSIBURU!
Try a million things...
Different kernel versions
Different filesystems tunings
Different security settings (GRSEC)
Different memory settings (overcommit, OOM)
Different instance sizes
Different EBS volumes
Different differences
NOTHING CHANGED
And one fine day...
A random test machine seems to exhibit the
bug very frequently (it would crash in a few
days, sometimes just a few hours).
CLONE IT!
ONE MILLION TIMES!
But, still...
We changed everything (again),
but we couldn’t find anything (again).
So we did something completely crazy:
we contacted AWS support (imagine that).
They asked us to repeat the tests with an
“official” image (AMI). This required porting
our runtime from Ubuntu 10.04 to 12.04.
And…(I’m running out of segues)
We re-ran the tests with the official image,
the machine crashed, we left it in crashed
state,
support analyzed the image.
Almost instanty, they told us
“oh yeah it’s a known issue,
see that link.”
U SERIOUS?
The explanation
The bug happens:
● on workloads using spinlocks intensively;
● only on Xen VMs with many CPUs.
It is linked to the special implementation of
spinlocks in Xen VMs.
When waking up CPUs waiting on a spinlock,
the code would only wake up the 1st one,
even if there were multiple CPUs waiting.
The patch (priceless)
diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
index d69cc6c..67bc7ba 100644
--- a/arch/x86/xen/spinlock.c
+++ b/arch/x86/xen/spinlock.c
@@ -328,7 +328,6 @@ static noinline void
xen_spin_unlock_slow(struct xen_spinlock
*xl)
if (per_cpu(lock_spinners, cpu) == xl) {
ADD_STATS(released_slow_kicked, 1);
xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
- break;
}
}
}
--
What did we learn?
We didn’t try all the combinations.
(Trying on HVM machines would have
helped!)
AWS support can be helpful sometimes.
(This one was a surprise.)
Trying to debug a kernel issue without console
output is like trying to learn to read in the
dark.
Overall Conclusions
When facing a mystic bug from outer space:
● reproduce it at all costs!
● collect data with tcpdump, ngrep, wireshark,
strace, ltrace, gdb; and log files, obviously!
● don’t be afraid of uncharted places!
● document it, at least with a 2 AM ragetweet!
Thank you! Questions?
Gotta follow them all:
@kwarter
@while_42
@GITSF
@dot_cloud
@docker
Your speaker today was:
Jérôme Petazzoni, dotCloud
@jpetazzo

Más contenido relacionado

La actualidad más candente

Once Upon a Process
Once Upon a ProcessOnce Upon a Process
Once Upon a ProcessDavid Evans
 
Solaris DTrace, An Introduction
Solaris DTrace, An IntroductionSolaris DTrace, An Introduction
Solaris DTrace, An Introductionsatyajit_t
 
JDK not so hidden treasures
JDK not so hidden treasuresJDK not so hidden treasures
JDK not so hidden treasuresAndrzej Grzesik
 
Linux Performance Tools 2014
Linux Performance Tools 2014Linux Performance Tools 2014
Linux Performance Tools 2014Brendan Gregg
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsDror Bereznitsky
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Jarod Wang
 
All of Your Network Monitoring is (probably) Wrong
All of Your Network Monitoring is (probably) WrongAll of Your Network Monitoring is (probably) Wrong
All of Your Network Monitoring is (probably) Wrongice799
 
Open Source Systems Performance
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems PerformanceBrendan Gregg
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsAndrei Pangin
 
FreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame GraphsFreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame GraphsBrendan Gregg
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactAlessandro Selli
 
JDK, the not so hidden treasures
JDK, the not so hidden treasuresJDK, the not so hidden treasures
JDK, the not so hidden treasuresAndrzej Grzesik
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsAndrei Pangin
 
Understanding Scratch Extensions with JavaScript (Part 2 of 2)
Understanding Scratch Extensions with JavaScript (Part 2 of 2)Understanding Scratch Extensions with JavaScript (Part 2 of 2)
Understanding Scratch Extensions with JavaScript (Part 2 of 2)Darren Adkinson
 
Active Web Development
Active Web DevelopmentActive Web Development
Active Web DevelopmentDivya Manian
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptDarren Adkinson
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Shuo Chen
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practicalMoabi.com
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slidesMoabi.com
 

La actualidad más candente (20)

Once Upon a Process
Once Upon a ProcessOnce Upon a Process
Once Upon a Process
 
Solaris DTrace, An Introduction
Solaris DTrace, An IntroductionSolaris DTrace, An Introduction
Solaris DTrace, An Introduction
 
JDK not so hidden treasures
JDK not so hidden treasuresJDK not so hidden treasures
JDK not so hidden treasures
 
Linux Performance Tools 2014
Linux Performance Tools 2014Linux Performance Tools 2014
Linux Performance Tools 2014
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
All of Your Network Monitoring is (probably) Wrong
All of Your Network Monitoring is (probably) WrongAll of Your Network Monitoring is (probably) Wrong
All of Your Network Monitoring is (probably) Wrong
 
Open Source Systems Performance
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems Performance
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
 
FreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame GraphsFreeBSD 2014 Flame Graphs
FreeBSD 2014 Flame Graphs
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
JDK, the not so hidden treasures
JDK, the not so hidden treasuresJDK, the not so hidden treasures
JDK, the not so hidden treasures
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap Dumps
 
Understanding Scratch Extensions with JavaScript (Part 2 of 2)
Understanding Scratch Extensions with JavaScript (Part 2 of 2)Understanding Scratch Extensions with JavaScript (Part 2 of 2)
Understanding Scratch Extensions with JavaScript (Part 2 of 2)
 
Active Web Development
Active Web DevelopmentActive Web Development
Active Web Development
 
Understanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScriptUnderstanding ScratchX Extensions with JavaScript
Understanding ScratchX Extensions with JavaScript
 
The Internet
The InternetThe Internet
The Internet
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++
 
[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical[Defcon] Hardware backdooring is practical
[Defcon] Hardware backdooring is practical
 
Hardware backdooring is practical : slides
Hardware backdooring is practical : slidesHardware backdooring is practical : slides
Hardware backdooring is practical : slides
 

Similar a Bugs from Outer Space | while42 SF #6

Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterEugene Kirpichov
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacPriyanka Aash
 
Kernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyKernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyAnne Nicolas
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioAndrey Karpov
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory AnalysisMoabi.com
 
OS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchOS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchDaniel Ben-Zvi
 
A User's Experience of Working with the Analyzer
A User's Experience of Working with the AnalyzerA User's Experience of Working with the Analyzer
A User's Experience of Working with the AnalyzerAndrey Karpov
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]RootedCON
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus44CON
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyAerospike
 
Easier, Better, Faster, Safer Deployment with Docker and Immutable Containers
Easier, Better, Faster, Safer Deployment with Docker and Immutable ContainersEasier, Better, Faster, Safer Deployment with Docker and Immutable Containers
Easier, Better, Faster, Safer Deployment with Docker and Immutable ContainersC4Media
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 
PVS-Studio and 3DO Emulators
PVS-Studio and 3DO EmulatorsPVS-Studio and 3DO Emulators
PVS-Studio and 3DO EmulatorsAndrey Karpov
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageablecorehard_by
 
Debugging multiplayer games
Debugging multiplayer gamesDebugging multiplayer games
Debugging multiplayer gamesMaciej Siniło
 
ruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Rubyruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in RubyCarlos Duarte do Nascimento
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer ReviewAndrey Karpov
 
Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Docker, Inc.
 

Similar a Bugs from Outer Space | while42 SF #6 (20)

Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core cluster
 
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attacDefcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
 
Kernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are moneyKernel Recipes 2019 - Metrics are money
Kernel Recipes 2019 - Metrics are money
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
 
[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
 
OS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switchOS scheduling and The anatomy of a context switch
OS scheduling and The anatomy of a context switch
 
A User's Experience of Working with the Analyzer
A User's Experience of Working with the AnalyzerA User's Experience of Working with the Analyzer
A User's Experience of Working with the Analyzer
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
 
Golang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war storyGolang Performance : microbenchmarks, profilers, and a war story
Golang Performance : microbenchmarks, profilers, and a war story
 
Easier, Better, Faster, Safer Deployment with Docker and Immutable Containers
Easier, Better, Faster, Safer Deployment with Docker and Immutable ContainersEasier, Better, Faster, Safer Deployment with Docker and Immutable Containers
Easier, Better, Faster, Safer Deployment with Docker and Immutable Containers
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
PVS-Studio and 3DO Emulators
PVS-Studio and 3DO EmulatorsPVS-Studio and 3DO Emulators
PVS-Studio and 3DO Emulators
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 
Debugging multiplayer games
Debugging multiplayer gamesDebugging multiplayer games
Debugging multiplayer games
 
ruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Rubyruby2600 - an Atari 2600 emulator written in Ruby
ruby2600 - an Atari 2600 emulator written in Ruby
 
CppCat Static Analyzer Review
CppCat Static Analyzer ReviewCppCat Static Analyzer Review
CppCat Static Analyzer Review
 
Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?Cgroups, namespaces and beyond: what are containers made from?
Cgroups, namespaces and beyond: what are containers made from?
 
x86 & PE
x86 & PEx86 & PE
x86 & PE
 

Más de While42

2 membres de while42 dans Programmez!
2 membres de while42 dans Programmez!2 membres de while42 dans Programmez!
2 membres de while42 dans Programmez!While42
 
while42 Marseille #1
while42 Marseille #1while42 Marseille #1
while42 Marseille #1While42
 
The Immigration reform
The Immigration reformThe Immigration reform
The Immigration reformWhile42
 
42 (school) at 2 years of while42
42 (school) at 2 years of while4242 (school) at 2 years of while42
42 (school) at 2 years of while42While42
 
La Silicon Valley vue par Camille Despringhere
La Silicon Valley vue par Camille DespringhereLa Silicon Valley vue par Camille Despringhere
La Silicon Valley vue par Camille DespringhereWhile42
 
Singapore chapitre #4 - You don't know
Singapore chapitre #4 - You don't knowSingapore chapitre #4 - You don't know
Singapore chapitre #4 - You don't knowWhile42
 
Singapore chapitre #4 - Presentation
Singapore chapitre #4 - PresentationSingapore chapitre #4 - Presentation
Singapore chapitre #4 - PresentationWhile42
 
while42 mentionné dans la version papier du quotidien "Le Monde"
while42 mentionné dans la version papier du quotidien "Le Monde"while42 mentionné dans la version papier du quotidien "Le Monde"
while42 mentionné dans la version papier du quotidien "Le Monde"While42
 
Qemu - Raspberry | while42 Singapore #2
Qemu - Raspberry | while42 Singapore #2Qemu - Raspberry | while42 Singapore #2
Qemu - Raspberry | while42 Singapore #2While42
 
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7Javascript sucks & frontend challenges @ClearSlide | while42 SF #7
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7While42
 
While42 SF presentation | w42 #7 at ClearSlide
While42 SF presentation | w42 #7 at ClearSlideWhile42 SF presentation | w42 #7 at ClearSlide
While42 SF presentation | w42 #7 at ClearSlideWhile42
 
while42 Montreal #0 @ wajam
while42 Montreal #0 @ wajamwhile42 Montreal #0 @ wajam
while42 Montreal #0 @ wajamWhile42
 
While42 SF #6: introducing while42 to Girls in Tech and Kwarter
While42 SF #6: introducing while42 to Girls in Tech and KwarterWhile42 SF #6: introducing while42 to Girls in Tech and Kwarter
While42 SF #6: introducing while42 to Girls in Tech and KwarterWhile42
 
While42 Paris #1 - Presentation de while42
While42 Paris #1 - Presentation de while42While42 Paris #1 - Presentation de while42
While42 Paris #1 - Presentation de while42While42
 
Hack le droid
Hack le droidHack le droid
Hack le droidWhile42
 

Más de While42 (15)

2 membres de while42 dans Programmez!
2 membres de while42 dans Programmez!2 membres de while42 dans Programmez!
2 membres de while42 dans Programmez!
 
while42 Marseille #1
while42 Marseille #1while42 Marseille #1
while42 Marseille #1
 
The Immigration reform
The Immigration reformThe Immigration reform
The Immigration reform
 
42 (school) at 2 years of while42
42 (school) at 2 years of while4242 (school) at 2 years of while42
42 (school) at 2 years of while42
 
La Silicon Valley vue par Camille Despringhere
La Silicon Valley vue par Camille DespringhereLa Silicon Valley vue par Camille Despringhere
La Silicon Valley vue par Camille Despringhere
 
Singapore chapitre #4 - You don't know
Singapore chapitre #4 - You don't knowSingapore chapitre #4 - You don't know
Singapore chapitre #4 - You don't know
 
Singapore chapitre #4 - Presentation
Singapore chapitre #4 - PresentationSingapore chapitre #4 - Presentation
Singapore chapitre #4 - Presentation
 
while42 mentionné dans la version papier du quotidien "Le Monde"
while42 mentionné dans la version papier du quotidien "Le Monde"while42 mentionné dans la version papier du quotidien "Le Monde"
while42 mentionné dans la version papier du quotidien "Le Monde"
 
Qemu - Raspberry | while42 Singapore #2
Qemu - Raspberry | while42 Singapore #2Qemu - Raspberry | while42 Singapore #2
Qemu - Raspberry | while42 Singapore #2
 
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7Javascript sucks & frontend challenges @ClearSlide | while42 SF #7
Javascript sucks & frontend challenges @ClearSlide | while42 SF #7
 
While42 SF presentation | w42 #7 at ClearSlide
While42 SF presentation | w42 #7 at ClearSlideWhile42 SF presentation | w42 #7 at ClearSlide
While42 SF presentation | w42 #7 at ClearSlide
 
while42 Montreal #0 @ wajam
while42 Montreal #0 @ wajamwhile42 Montreal #0 @ wajam
while42 Montreal #0 @ wajam
 
While42 SF #6: introducing while42 to Girls in Tech and Kwarter
While42 SF #6: introducing while42 to Girls in Tech and KwarterWhile42 SF #6: introducing while42 to Girls in Tech and Kwarter
While42 SF #6: introducing while42 to Girls in Tech and Kwarter
 
While42 Paris #1 - Presentation de while42
While42 Paris #1 - Presentation de while42While42 Paris #1 - Presentation de while42
While42 Paris #1 - Presentation de while42
 
Hack le droid
Hack le droidHack le droid
Hack le droid
 

Último

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Bugs from Outer Space | while42 SF #6

  • 1. Bugs From Outer Space While42 — SF chapter — #6
  • 2.
  • 3. Why this talk? Codito, ergo erro I code, therefore I make mistakes
  • 4. Outline I'll show some really nasty bugs, tell stories of unglorious battles. (Some of which I've actually fought!) Featuring: Node.js, EC2, LXC, pseudo- terminals and also: hardware bugs, dangerous bugs...
  • 5. Our files, Node.js is truncating them! It all starts with an angry customer. “Sometimes, downloading this 700 KB JSON file will fail, because it’s truncated!” But… Do you even Content-Length? (The client library should scream, but it doesn’t.)
  • 6. Gotta Sniff Some Packets Log into the load balancer (running Hipache)... # ngrep -tipd any -Wbyline '/api/v1/download-all-the-things' tcp port 80 interface: any filter: (ip or ip6) and ( tcp port 80 ) match: /api/v1/download-all-the-things #### T 2013/08/22 04:11:27.848663 23.20.88.251:55983 -> 10.116.195.150:80 [AP] GET /api/v1/download-all-the-things.json HTTP/1.0. Host: angrystartup.com X-Forwarded-Port: 443. X-Forwarded-For: ::ffff:24.13.146.16. X-Forwarded-Proto: https. ...
  • 7. Ngrep Doesn’t Cut It. FETCH THE WIRESHARKS! # tcpdump -peni any -s0 -wdump tcp port 80 (Wait a bit) ^C Transfer dump file DEMO TIME!
  • 8.
  • 9. What did we find out? Truncated files happen because a chunk (probably exactly one) gets dropped. Impossible to reproduce locally. Only the customer sees the problem. THE PLOT THICKENS. GET YOUR SWIMSUITS, WE’RE DIVING INTO CODE!
  • 10. This is Node.js.I have no idea what I’m doing. Add console.log() statements in Hipache. Add console.log() statements in node-http- proxy. Add console.log() statements in node/lib/http.js. The latter didn’t work. “Fix”: replace require(‘http’) with require(‘_http’) and add our own _http.js to our node_modules. Do the same to net.js (in “our” _http.js).
  • 11. It’s all in the pauses Backend sends lots of data to Hipache. Hipache sends data to client, but client is slow. Hipache “pauses” the backend stream. (i.e. stops reading from the network socket.) When the client has read enough data, Hipache “resumes” the stream. etc. SO FAR, SO GOOD
  • 12. It’s all in the awkward ……………………...pauses There are two layers in Node: tcp and http. When the tcp layer reads the last chunk, the socket is closed by the backend. The tcp layer notices, and sends an “end” event. The “end” event causes the “http” layer to finish what it was doing, without sending a “resume”. As a result, some chunks remain in the buffers
  • 13. How do we fix this? Pester Node.js folks Catch that “end” event, and when it happens, send a “resume” to the stream to drain it. (Implementation detail: you only have the http socket, and you need to listen for an event on the tcp socket, so you need to do slightly dirty things with the http socket. But eh, it works!)
  • 14.
  • 15. What did we learn? When you can’t reproduce a bug at will, record it in action (tcpdump) and dissect it (wireshark). Spraying code with print statements helps. (But it’s better to use the logging framework!) You don’t have to know Node.js to fix Node.js!
  • 16. Hardware has bugs, too Pentium FDIV bug (1994): errors at 4th decimal place Pentium F00F bug (1997): using the wrong instruction hangs the machine ATA transfer speeds vary when you touch ribbon cables (SATA introduced in 2003)
  • 17. A story of Go, PTYs, LXC: It never works the first time # docker run -t -i ubuntu echo hello world 2013/08/06 23:20:53 Error: Error starting container 06d642aae1a: fork/exec /usr/bin/lxc-start: operation not permitted # docker run -t -i ubuntu echo hello world hello world # docker run -t -i ubuntu echo hello world hello world # docker run -t -i ubuntu echo hello world hello world # docker run -t -i ubuntu echo hello world hello world
  • 18.
  • 19. Strace to the rescue! Steps: 1. Boot the machine. 2. Find pid of process to analyze. (ps|grep, pidof docker...) 3. “strace -o log -f -p $PID” 4. “docker run -t -i run ubuntu echo hello world” 5. Ctrl-C the strace process. 6. Repeat steps 3-4-5, using a different log file.
  • 20. Let’s compare the log files Thousands and thousands of lines. Look for the error message. (e.g. “operation not permitted”) Other approach: start from the end, and try to find the point when things started to diverge. That’s why we have dual 30” monitors.
  • 21. Investigation results First time [pid 1331] setsid() = 1331 [pid 1331] dup2(10, 0) = 0 [pid 1331] dup2(10, 1) = 1 [pid 1331] dup2(10, 2) = 2[pid 1331] ioctl(0, TIOCSCTTY) = -1 EPERM (Operation not permitted)[pid 1331] write(12, "10000000", 8) = 8 [pid 1331] _exit(253) = ? Second time (and every following attempt) [pid 1414] setsid() = 1414 [pid 1414] dup2(14, 0) = 0 [pid 1414] dup2(14, 1) = 1 [pid 1414] dup2(14, 2) = 2[pid 1414] ioctl(0, TIOCSCTTY) = 0[pid 1414] execve("/usr/bin/lxc-start", ["lxc- start", "-n", ...]) <...>
  • 22. What does that mean? For some reason, some part of the code wants file descriptor 0 (that’s stdin) to be a terminal. The first time we run, it fails, but in the process, we acquire a terminal. (UNIX 101: when you don’t have a controlling terminal and open a file which is a terminal, it becomes your controlling terminal, unless you open the file with flag O_NOCTTY) Next attempts are therefore successful.
  • 23. … Really? To confirm that this is indeed the bug: ● start the process with “setsid” (which detaches from the controlling terminal) and see that the bug is back; ● check the output of “ps” (it shows controlling terminals) and see that indeed, before the first execution, we didn’t have a controlling terminal, and we have one after!
  • 24. How to fix the bug? ¯_(ツ)_/¯ I don’t know — yet! (The bug was diagnosed last week, and honestly, it’s not a showstopper.)
  • 25. What did we learn? strace is awesome to analyze behavior of running processes. ltrace can be used, too, if you want to analyze library calls rather than system calls. If you’re really desperate, gdb is your friend. (A very peculiar friend, but a friend nonetheless.)
  • 26. “Errare humanum est, perseverare autem diabolicum” “To err is human, but to really foul things up, you need a computer”
  • 27. Really nasty (and sad) bug: The Therac-25 Radiotherapy machine (shoots beams to cure cancer) Two modes: low energy and high energy. In high energy mode, a special filter is inserted. In other versions, a hardware system prevented the high energy beam from shooting if the filter was not in place. On the Therac-25, it’s in software.
  • 28. Konami Code of Death On the keyboard, press (in less than 8 seconds) X ↑ E [ENTER] B ...And the high energy beam shoots, unfiltered! 6 accidents, 3 died. (This was 1985-1987.) Explanation: race condition in the software. Never happened during tests since this was
  • 29. Aggravating details Many engineering and institutional issues.(No software review, no evaluation of possible failures, undocumented error codes, no sensor feedback…) After entering the sequence and sending one beam, the machine would display an error. But errors happened “all the time” (usually without adverse effect) so the operator would just proceed (equivalent of pressing “retry”).
  • 30. Let’s get back to weird Linux Kernel bugs
  • 31. Random crashes on EC2 Pool of ~50 identical instances, with same role. Sometimes, one of them would crash. Total crash: no SSH, no ping, no log, no nothing. EC2 console won’t show anything. REPRODUCE THE BUG? IMPOSSIBURU!
  • 32. Try a million things... Different kernel versions Different filesystems tunings Different security settings (GRSEC) Different memory settings (overcommit, OOM) Different instance sizes Different EBS volumes Different differences NOTHING CHANGED
  • 33. And one fine day... A random test machine seems to exhibit the bug very frequently (it would crash in a few days, sometimes just a few hours). CLONE IT! ONE MILLION TIMES!
  • 34. But, still... We changed everything (again), but we couldn’t find anything (again). So we did something completely crazy: we contacted AWS support (imagine that). They asked us to repeat the tests with an “official” image (AMI). This required porting our runtime from Ubuntu 10.04 to 12.04.
  • 35. And…(I’m running out of segues) We re-ran the tests with the official image, the machine crashed, we left it in crashed state, support analyzed the image. Almost instanty, they told us “oh yeah it’s a known issue, see that link.” U SERIOUS?
  • 36. The explanation The bug happens: ● on workloads using spinlocks intensively; ● only on Xen VMs with many CPUs. It is linked to the special implementation of spinlocks in Xen VMs. When waking up CPUs waiting on a spinlock, the code would only wake up the 1st one, even if there were multiple CPUs waiting.
  • 37. The patch (priceless) diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c index d69cc6c..67bc7ba 100644 --- a/arch/x86/xen/spinlock.c +++ b/arch/x86/xen/spinlock.c @@ -328,7 +328,6 @@ static noinline void xen_spin_unlock_slow(struct xen_spinlock *xl) if (per_cpu(lock_spinners, cpu) == xl) { ADD_STATS(released_slow_kicked, 1); xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR); - break; } } } --
  • 38. What did we learn? We didn’t try all the combinations. (Trying on HVM machines would have helped!) AWS support can be helpful sometimes. (This one was a surprise.) Trying to debug a kernel issue without console output is like trying to learn to read in the dark.
  • 39.
  • 40. Overall Conclusions When facing a mystic bug from outer space: ● reproduce it at all costs! ● collect data with tcpdump, ngrep, wireshark, strace, ltrace, gdb; and log files, obviously! ● don’t be afraid of uncharted places! ● document it, at least with a 2 AM ragetweet!
  • 41. Thank you! Questions? Gotta follow them all: @kwarter @while_42 @GITSF @dot_cloud @docker Your speaker today was: Jérôme Petazzoni, dotCloud @jpetazzo