summaryrefslogtreecommitdiffstats
path: root/archives/extend/2013-July/000159.html
blob: cf096ef30a95590cb3c2326b1929d3bdfadb681b (plain) (blame)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
 <HEAD>
   <TITLE> [99s-extend] Cowboy handler linked processes
   </TITLE>
   <LINK REL="Index" HREF="index.html" >
   <LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20handler%20linked%20processes&In-Reply-To=%3C66E9A8B267A946AF8F527593BBFD26B0%40id3as.co.uk%3E">
   <META NAME="robots" CONTENT="index,nofollow">
   <style type="text/css">
       pre {
           white-space: pre-wrap;       /* css-2.1, curent FF, Opera, Safari */
           }
   </style>
   <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
   <LINK REL="Previous"  HREF="000158.html">
   <LINK REL="Next"  HREF="000160.html">
 </HEAD>
 <BODY BGCOLOR="#ffffff">
   <H1>[99s-extend] Cowboy handler linked processes</H1>
    <B>Adrian Roe</B> 
    <A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20handler%20linked%20processes&In-Reply-To=%3C66E9A8B267A946AF8F527593BBFD26B0%40id3as.co.uk%3E"
       TITLE="[99s-extend] Cowboy handler linked processes">adrian at id3as.co.uk
       </A><BR>
    <I>Thu Jul 18 12:37:30 CEST 2013</I>
    <P><UL>
        <LI>Previous message: <A HREF="000158.html">[99s-extend] Cowboy handler linked processes
</A></li>
        <LI>Next message: <A HREF="000160.html">[99s-extend] Cowboy handler linked processes
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#159">[ date ]</a>
              <a href="thread.html#159">[ thread ]</a>
              <a href="subject.html#159">[ subject ]</a>
              <a href="author.html#159">[ author ]</a>
         </LI>
       </UL>
    <HR>  
<!--beginarticle-->
<PRE>That would be perfect!  Do you want me to make the change and issue a pull request?  

--  
Dr Adrian Roe
Director


On Thursday, 18 July 2013 at 11:36, Lo&#239;c Hoguin wrote:

&gt;<i> I don't think the problem is that the handler is reused, we don't reuse  
</I>&gt;<i> them if there's an error. However we do catch errors to print them in  
</I>&gt;<i> the logs, and then the process stops normally. If you link without  
</I>&gt;<i> trap_exit you receive a normal exit signal which is ignored and doesn't  
</I>&gt;<i> kill your process. I suppose we should throw an exit signal when we got  
</I>&gt;<i> an error, after logging everything, instead of stopping normally.
</I>&gt;<i>  
</I>&gt;<i> On 07/18/2013 12:31 PM, Adrian Roe wrote:
</I>&gt;<i> &gt; My issue is the other way round. My handler crashes - and terminate
</I>&gt;<i> &gt; gets called, but the linked process is NOT stopped (unless I stop it in
</I>&gt;<i> &gt; terminate having stashed any processes I need to stop in the process
</I>&gt;<i> &gt; dictionary - this is what I'm currently doing, but yuck!)
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt; . My question is whether it wouldn't be better to no re-use the handler
</I>&gt;<i> &gt; process that has crashed and replace it so that handler's can use the
</I>&gt;<i> &gt; canonical erlang way of stopping related processes rather than having to
</I>&gt;<i> &gt; do it by hand.
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt; Obviously if the handler does not crash there's no need to kill the
</I>&gt;<i> &gt; process, so the current efficiency saving works in the &quot;normal&quot; case/
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt; --
</I>&gt;<i> &gt; Dr Adrian Roe
</I>&gt;<i> &gt; Director
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt; On Thursday, 18 July 2013 at 11:20, Lo&#239;c Hoguin wrote:
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt; &gt; I don't know what happens but there's two things I know:
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt; * Handlers don't trap_exit, so if the linked process crashes, they
</I>&gt;<i> &gt; &gt; crash too
</I>&gt;<i> &gt; &gt; * If the handler crashes, we close the connection and stop the
</I>&gt;<i> &gt; &gt; handler; if not this is a bug
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt; After your log message the handler should stop unless there's a bug
</I>&gt;<i> &gt; &gt; somewhere.
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt; On 07/18/2013 12:15 PM, Adrian Roe wrote:
</I>&gt;<i> &gt; &gt; &gt; We have been using spawn_linked workers to handle tasks that live for
</I>&gt;<i> &gt; &gt; &gt; the lifetime of a single HTTP request
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; Although in the cowboy guide it is clear that Cowboy can use &quot;One
</I>&gt;<i> &gt; &gt; &gt; Process of Many Requests&quot; I am surprised that this is the case even if
</I>&gt;<i> &gt; &gt; &gt; the handler crashes. For example, our use case is to copy a large file
</I>&gt;<i> &gt; &gt; &gt; to the server over HTTP where a worker process relays the file contents
</I>&gt;<i> &gt; &gt; &gt; to long term storage. The worker process is spawn_linked from the HTTP
</I>&gt;<i> &gt; &gt; &gt; handler and (for our use case) should die if the handler stops.
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; If the client stops the upload (for example by browsing away, or losing
</I>&gt;<i> &gt; &gt; &gt; connectivity) we correctly receive an error (see sample Lager trace
</I>&gt;<i> &gt; &gt; &gt; below), but what we are seeing is that spawn_linked processes are NOT
</I>&gt;<i> &gt; &gt; &gt; being killed.
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; Is this intended behaviour - I accept it makes sense to reuse the
</I>&gt;<i> &gt; &gt; &gt; processes but should this continue to be the case even if the previous
</I>&gt;<i> &gt; &gt; &gt; use of the process crashed? If it is intended behaviour I think the
</I>&gt;<i> &gt; &gt; &gt; docs should highlight this as we've been leaking processes for some time
</I>&gt;<i> &gt; &gt; &gt; now, but I've always seen it as erlang's job to look after related
</I>&gt;<i> &gt; &gt; &gt; process trees in the event of error. Our current workaround is to hold
</I>&gt;<i> &gt; &gt; &gt; a list of linked processes in process storage and then kill them in the
</I>&gt;<i> &gt; &gt; &gt; terminate handler which is ugly in the extreme!! We don't know the PIDS
</I>&gt;<i> &gt; &gt; &gt; of the linked processes until it is too late to return State to Cowboy
</I>&gt;<i> &gt; &gt; &gt; (i.e. we are already in our handle code)...
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; Kind regards
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; Adrian
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; 16:09:32.347 [info] Trailer upload failed with reason
</I>&gt;<i> &gt; &gt; &gt; {case_clause,{error,closed}}
</I>&gt;<i> &gt; &gt; &gt; 16:09:32.348 [error] ** Cowboy handler upload_trailer_resource
</I>&gt;<i> &gt; &gt; &gt; terminating in handle/2
</I>&gt;<i> &gt; &gt; &gt; for the reason error:{case_clause,{error,closed}}
</I>&gt;<i> &gt; &gt; &gt; ** Handler state was {state,undefined,0,undefined,undefined,undefined}
</I>&gt;<i> &gt; &gt; &gt; ** Request was
</I>&gt;<i> &gt; &gt; &gt; [{socket,#Port&lt;0.11230&gt;},{transport,ranch_tcp},{connection,keepalive},{pid,&lt;0.1987.0&gt;},{method,&lt;&lt;&quot;POST&quot;&gt;&gt;},{version,'HTTP/1.1'},{peer,{{84,92,32,116},64136}},{host,&lt;&lt;&quot;54.225.117.108&quot;&gt;&gt;},{host_info,undefined},{port,8000},{path,&lt;&lt;&quot;/upload_trailer&quot;&gt;&gt;},{path_info,undef
</I>&gt;<i> &gt; &gt; &gt; ined},{qs,&lt;&lt;&quot;name=linux-7.4.21.zip&amp;size=54015414&quot;&gt;&gt;},{qs_vals,undefined},{bindings,[]},{headers,[{&lt;&lt;&quot;host&quot;&gt;&gt;,&lt;&lt;&quot;54.225.117.108:8000&quot;&gt;&gt;},{&lt;&lt;&quot;connection&quot;&gt;&gt;,&lt;&lt;&quot;keep-alive&quot;&gt;&gt;},{&lt;&lt;&quot;content-length&quot;&gt;&gt;,&lt;&lt;&quot;54015414&quot;&gt;&gt;},{&lt;&lt;&quot;origin&quot;&gt;&gt;,&lt;&lt;&quot;<A HREF="http://54.225.117.108:8000">http://54.225.117.108:8000</A>&quot;&gt;&gt;},{&lt;&lt;&quot;user-agent&quot;&gt;&gt;,&lt;&lt;&quot;M
</I>&gt;<i> &gt; &gt; &gt; ozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML,
</I>&gt;<i> &gt; &gt; &gt; like Gecko) Chrome/28.0.1500.71
</I>&gt;<i> &gt; &gt; &gt; Safari/537.36&quot;&gt;&gt;},{&lt;&lt;&quot;content-type&quot;&gt;&gt;,&lt;&lt;&gt;&gt;},{&lt;&lt;&quot;accept&quot;&gt;&gt;,&lt;&lt;&quot;*/*&quot;&gt;&gt;},{&lt;&lt;&quot;referer&quot;&gt;&gt;,&lt;&lt;&quot;<A HREF="http://54.225.117.108:8000/">http://54.225.117.108:8000/</A>&quot;&gt;&gt;},{&lt;&lt;&quot;accept-encoding&quot;&gt;&gt;,&lt;&lt;&quot;gzip,deflate,sdch&quot;&gt;&gt;},{&lt;&lt;&quot;acce
</I>&gt;<i> &gt; &gt; &gt; pt-language&quot;&gt;&gt;,&lt;&lt;&quot;en-US,en;q=0.8&quot;&gt;&gt;},{&lt;&lt;&quot;cookie&quot;&gt;&gt;,&lt;&lt;&quot;__jwpusr=cbc133d7-1b49-443c-8a13-364660cc93e5;
</I>&gt;<i> &gt; &gt; &gt; id3as_manager=f4803c004d71dde3b64394f6e6f44faa54970e93&quot;&gt;&gt;}]},{p_headers,[{&lt;&lt;&quot;connection&quot;&gt;&gt;,[&lt;&lt;&quot;keep-alive&quot;&gt;&gt;]}]},{cookies,undefined},{meta,[]},{body_state,waiting},{multipart,unde
</I>&gt;<i> &gt; &gt; &gt; fined},{buffer,&lt;&lt;&gt;&gt;},{resp_compress,true},{resp_state,waiting},{resp_headers,[]},{resp_body,&lt;&lt;&gt;&gt;},{onresponse,undefined}]
</I>&gt;<i> &gt; &gt; &gt; ** Stacktrace:
</I>&gt;<i> &gt; &gt; &gt; [{i_cowboy,stream_body,0,[{file,&quot;src/i_cowboy.erl&quot;},{line,76}]},{upload_trailer_resource,stream_upload_file,4,[{file,&quot;src/endpoints/upload_trailer_resource.erl&quot;},{line,247}]},{upload_trailer_resource,upload_file,1,[{file,&quot;src/endpoints/upload_trailer_resource.erl&quot;}
</I>&gt;<i> &gt; &gt; &gt; ,{line,237}]},{upload_trailer_resource,head_or_post,1,[{file,&quot;src/endpoints/upload_trailer_resource.erl&quot;},{line,202}]},{upload_trailer_resource,sequence,2,[{file,&quot;src/endpoints/upload_trailer_resource.erl&quot;},{line,106}]},{upload_trailer_resource,process_request,1,[{file,&quot;src/endpo
</I>&gt;<i> &gt; &gt; &gt; ints/upload_trailer_resource.erl&quot;},{line,212}]},{i_cowboy,do,3,[{file,&quot;src/i_cowboy.erl&quot;},{line,29}]},{cowboy_handler,handler_handle,4,[{file,&quot;src/cowboy_handler.erl&quot;},{line,119}]}]
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; --
</I>&gt;<i> &gt; &gt; &gt; Dr Adrian Roe
</I>&gt;<i> &gt; &gt; &gt; Director
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt; &gt; _______________________________________________
</I>&gt;<i> &gt; &gt; &gt; Extend mailing list
</I>&gt;<i> &gt; &gt; &gt; <A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A> &lt;mailto:<A HREF="https://lists.ninenines.eu/listinfo/extend">Extend at lists.ninenines.eu</A>&gt;
</I>&gt;<i> &gt; &gt; &gt; <A HREF="http://lists.ninenines.eu:81/listinfo/extend">http://lists.ninenines.eu:81/listinfo/extend</A>
</I>&gt;<i> &gt; &gt; &gt;  
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt; &gt; --
</I>&gt;<i> &gt; &gt; Lo&#239;c Hoguin
</I>&gt;<i> &gt; &gt; Erlang Cowboy
</I>&gt;<i> &gt; &gt; Nine Nines
</I>&gt;<i> &gt; &gt; <A HREF="http://ninenines.eu">http://ninenines.eu</A>
</I>&gt;<i> &gt; &gt;  
</I>&gt;<i> &gt;  
</I>&gt;<i> &gt;  
</I>&gt;<i>  
</I>&gt;<i>  
</I>&gt;<i>  
</I>&gt;<i> --  
</I>&gt;<i> Lo&#239;c Hoguin
</I>&gt;<i> Erlang Cowboy
</I>&gt;<i> Nine Nines
</I>&gt;<i> <A HREF="http://ninenines.eu">http://ninenines.eu</A>
</I>&gt;<i>  
</I>&gt;<i>  
</I>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: &lt;<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20130718/79e075b8/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20130718/79e075b8/attachment.html</A>&gt;
</PRE>

<!--endarticle-->
    <HR>
    <P><UL>
        <!--threads-->
	<LI>Previous message: <A HREF="000158.html">[99s-extend] Cowboy handler linked processes
</A></li>
	<LI>Next message: <A HREF="000160.html">[99s-extend] Cowboy handler linked processes
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#159">[ date ]</a>
              <a href="thread.html#159">[ thread ]</a>
              <a href="subject.html#159">[ subject ]</a>
              <a href="author.html#159">[ author ]</a>
         </LI>
       </UL>

<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>