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':
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':
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':
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