-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2021-07-03-the-timeout-manager-exception.html
115 lines (99 loc) · 6.06 KB
/
2021-07-03-the-timeout-manager-exception.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="alternate"
type="application/rss+xml"
href="https://magnus.therning.org/feed.xml"
title="RSS feed for https://magnus.therning.org/">
<title>The timeout manager exception</title>
<meta name="author" content="Magnus Therning"><meta name="referrer" content="no-referrer"><link href= "static/style.css" rel="stylesheet" type="text/css" /><link href= "static/htmlize.css" rel="stylesheet" type="text/css" /><link href= "static/extra_style.css" rel="stylesheet" type="text/css" /></head>
<body>
<div id="preamble" class="status"><div class="nav-bar"><a class="nav-link" href="./index.html">Top</a><a class="nav-link" href="./archive.html">Archive</a><a class="nav-link align-right" href="./feed.xml"><img src="static/rss-feed-icon.png" style="height: 24px;" /></a></div></div>
<div id="content">
<div class="post-date">03 Jul 2021</div><h1 class="post-title"><a href="https://magnus.therning.org/2021-07-03-the-timeout-manager-exception.html">The timeout manager exception</a></h1>
<p>
The other day I bumped the dependencies of a Haskell project at work and noticed
a new exception being thrown:
</p>
<blockquote>
<p>
Thread killed by timeout manager
</p>
</blockquote>
<p>
After a couple of false starts (it wasn't the <a href="https://hackage.haskell.org/package/resource-pool">connection pool</a>, nor was it
<a href="https://hackage.haskell.org/package/servant">servant</a>) I realised that a better approach would be to look at the list of
packages that were updated as part of the dependency bumping.<sup><a id="fnr.1" class="footref" href="#fn.1">1</a></sup> Most of them
I thought would be <span class="underline">very</span> unlikely sources of it, but two in the list stood out:
</p>
<table>
<colgroup>
<col class="org-left">
<col class="org-right">
<col class="org-right">
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Package</th>
<th scope="col" class="org-right">Pre</th>
<th scope="col" class="org-right">Post</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><a href="https://hackage.haskell.org/package/unliftio">unliftio</a></td>
<td class="org-right">0.2.14</td>
<td class="org-right">0.2.18</td>
</tr>
<tr>
<td class="org-left"><a href="https://hackage.haskell.org/package/warp">warp</a></td>
<td class="org-right">3.3.15</td>
<td class="org-right">3.3.16</td>
</tr>
</tbody>
</table>
<p>
<code>warp</code> since the exception seemed to be thrown shortly after handling an HTTP
request, and <code>unliftio</code> since the exception was caught by the handler for
uncaught exceptions and its description contains "thread". Also, when looking at
the code changes in <code>warp</code> on GitHub<sup><a id="fnr.2" class="footref" href="#fn.2">2</a></sup> I found that some of the changes
introduced was increased use of <code>unliftio</code> for async stuff. The changes contain
mentions of <code>TimeoutThread</code> and <code>System.TimeManager</code>. That sounded promising,
and it lead me to the <a href="https://hackage.haskell.org/package/time-manager-0.0.0/docs/System-TimeManager.html#t:TimeoutThread">TimeoutThread</a> exception in <a href="https://hackage.haskell.org/package/time-manager">time-manager</a>.
</p>
<p>
With that knowledge I could quickly adjust the handler for uncaught exceptions
to not log <code>TimeoutThread</code> as fatal:
</p>
<div class="org-src-container">
<pre class="src src-haskell"><span class="org-haskell-definition">lastExceptionHandler</span> <span class="org-haskell-operator">::</span> <span class="org-haskell-type">LoggerSet</span> <span class="org-haskell-operator">-></span> <span class="org-haskell-type">SomeException</span> <span class="org-haskell-operator">-></span> <span class="org-haskell-type">IO</span> <span class="org-haskell-constructor"><span class="org-rainbow-delimiters-depth-1">()</span></span>
<span class="org-haskell-definition">lastExceptionHandler</span> logger e
<span class="org-haskell-operator">|</span> <span class="org-haskell-constructor">Just</span> <span class="org-haskell-constructor">TimeoutThread</span> <span class="org-haskell-operator"><-</span> fromException e <span class="org-haskell-operator">=</span> return <span class="org-haskell-constructor"><span class="org-rainbow-delimiters-depth-1">()</span></span>
<span class="org-haskell-operator">|</span> otherwise <span class="org-haskell-operator">=</span> <span class="org-haskell-keyword">do</span>
logFatalIoS logger <span class="org-haskell-operator">$</span> pack <span class="org-haskell-operator">$</span> <span class="org-string">"uncaught exception: "</span> <span class="org-haskell-operator"><></span> displayException e
flushLogStr logger
</pre>
</div>
<p>
I have to say it was a bit more work to arrive at this than I'd have liked. I
reckon there are easier ways to track down the information I needed. So I'd love
to hear what tricks and tips others have.
</p>
<div id="footnotes">
<h2 class="footnotes">Footnotes: </h2>
<div id="text-footnotes">
<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1">1</a></sup> <div class="footpara"><p class="footpara">
As a bonus it gave me a good reason to reach for <a href="https://man7.org/linux/man-pages/man1/comm.1.html"><code>comm</code></a>, a command that I
rarely use but for some reason always enjoy.
</p></div></div>
<div class="footdef"><sup><a id="fn.2" class="footnum" href="#fnr.2">2</a></sup> <div class="footpara"><p class="footpara">
GitHub's compare feature isn't very easy to discover, but a URL like this
<a href="https://github.com/yesodweb/wai/compare/warp-3.3.15...warp-3.3.16">https://github.com/yesodweb/wai/compare/warp-3.3.15…warp-3.3.16</a> (note the 3
dots!) does the trick.
</p></div></div>
</div>
</div><div class="taglist"><a href="https://magnus.therning.org/tags.html">Tags</a>: <a href="https://magnus.therning.org/tag-haskell.html">haskell</a> <a href="https://magnus.therning.org/tag-warp.html">warp</a> <a href="https://magnus.therning.org/tag-servant.html">servant</a> </div></div>
<div id="postamble" class="status"><!-- org-static-blog-page-postamble --></div>
</body>
</html>