How to handle TerminateSessionException sendfile?

33 views
Skip to first unread message

Henry Laxen

unread,
May 20, 2017, 10:33:29 PM5/20/17
to Snap Framework
Dear Snappers,

I've been using Snap for a few years now, and every few days I get an email like this:

snip
...
177.192.105.60 - - [20/May/2017:21:25:42 -0400] "GET /static/favicon.ico HTTP/1.1" 200 3638 "http://maztravel.com/haskell/mySqlToCouchDB.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
------------------------------------------------------------------------
A web handler threw an exception. Details:
sendfile: resource vanished (Connection reset by peer)
[20/May/2017:16:28:56 -0400] Exception leaked to httpSession during phase 'user handler': 
During processing of request from 86.143.35.116:58136
request:
"GET /us/houses/reno/images/large/reno_n_bath1.jpg HTTP/1.1
connection: Keep-Alive
accept-encoding: gzip, deflate
user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
accept-language: en-GB
accept: image/png, image/svg+xml, image/jxr, image/*;q=0.8, */*;q=0.5
A web handler threw an exception. Details:
TerminateSessionException sendfile: resource vanished (Connection reset by peer)
[20/May/2017:18:06:32 -0400] Exception leaked to httpSession during phase 'sending-response': 
During processing of request from 172.56.20.36:42168
request:
"GET /maz/images/large/peso10a.jpg HTTP/1.1
user-agent: com.google.GoogleMobile/27.0.0 iPhone/10.2 hw/iPhone8_1
accept-encoding: gzip, deflate
connection: keep-alive
accept-language: en-us
accept: */*
A web handler threw an exception. Details:
sendfile: resource vanished (Broken pipe)
[20/May/2017:18:06:32 -0400] Exception leaked to httpSession during phase 'user handler': 
During processing of request from 172.56.20.36:42168
request:
"GET /maz/images/large/peso10a.jpg HTTP/1.1
user-agent: com.google.GoogleMobile/27.0.0 iPhone/10.2 hw/iPhone8_1
accept-encoding: gzip, deflate
connection: keep-alive
accept-language: en-us
accept: */*
A web handler threw an exception. Details:
TerminateSessionException sendfile: resource vanished (Broken pipe)


which has made me resort to a shell wrapper around my snap server (called nlh):

while [ 1 ]; do
   
./nlh -p 80
    tail
-20 log/access.log >access.txt
    tail
-20 log/error.log  >error.txt
    cat access
.txt divider.txt error.txt | mail -s "NLH crash" nadine.and.henry@pobox.com
done



So my question is how can I catch this exception in my code so
that it doesn't escape to the top level.  The files above are
static files being served by the following lines in the depths
of the nlh code:

import           Snap.Util.FileServe
...


myServeFile  
:: MonadSnap m => FilePath -> m ()
myServeFile fp
= do
  setReferer
-- just sets the Referer header
 
when isVideo $ extendTimeout (5 * 60)
----------------------------
  serveFileAs mimeType fp
-- from Snap.Util.FileServe
----------------------------
 
where
    mimeType
= fileType myMimeTypes (takeFileName fp)
    isVideo
= B8.take (length ("video" :: String)) mimeType ==  "video"



Any pointers would be appreicated.
Best wishes,
Henry Laxen

Gregory Collins

unread,
Jun 8, 2017, 9:05:42 AM6/8/17
to snap_fr...@googlegroups.com
You can wrap your snap monad action in the exception functions from Control.Exception.Lifted. You can also replace the toplevel exception handler via setErrorHandler.

--

---
You received this message because you are subscribed to the Google Groups "Snap Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snap_framework+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Gregory Collins <gr...@gregorycollins.net>
Reply all
Reply to author
Forward
0 new messages