on master help sign in
Separate connClose and connFree

Thanks to @lehins for figuring out that this was causing the segfault

commitb63ec0e865cf91af4143416adaf430969ba0ebb5 authorMichael Snoyman <michael@snoyman.com> dateTue 24 Jan 2017, 16:57 (10 years ago) parent3eb5866
6 files changed+20−7
warp-tls/Network/Wai/Handler/WarpTLS.hs+2−2 warp-tls/warp-tls.cabal+1−1 warp/ChangeLog.md+6 warp/Network/Wai/Handler/Warp/Run.hs+4−2 warp/Network/Wai/Handler/Warp/Types.hs+6−1 warp/warp.cabal+1−1
warp-tls/Network/Wai/Handler/WarpTLS.hs+2−2
@@ -345,6 +345,7 @@ httpOverTls TLSSettings{..} s bs0 params = do
345345 , connSendAll = sendall
346346 , connSendFile = sendfile
347347 , connClose = close'
348+ , connFree = freeBuffer writeBuf
348349 , connRecv = recv ref
349350 , connRecvBuf = recvBuf ref
350351 , connWriteBuffer = writeBuf
@@ -355,8 +356,7 @@ httpOverTls TLSSettings{..} s bs0 params = do
355356 sendfile fid offset len hook headers =
356357 readSendFile writeBuf bufferSize sendall fid offset len hook headers
357358
358− close' = freeBuffer writeBuf `finally`
359− void (tryIO $ TLS.bye ctx) `finally`
359+ close' = void (tryIO $ TLS.bye ctx) `finally`
360360 TLS.contextClose ctx
361361
362362 -- TLS version of recv with a cache for leftover input data.
warp-tls/warp-tls.cabal+1−1
@@ -21,7 +21,7 @@ Library
2121 Build-Depends: base >= 4 && < 5
2222 , bytestring >= 0.9
2323 , wai >= 3.2 && < 3.3
24− , warp >= 3.2 && < 3.3
24+ , warp >= 3.2.10 && < 3.3
2525 , data-default-class >= 0.0.1
2626 , tls >= 1.3.5
2727 , cryptonite >= 0.12
warp/ChangeLog.md+6
@@ -1,3 +1,9 @@
1+## 3.2.10
2+
3+* Add `connFree` to `Connection`
4+* Close socket connections on timeout triggered
5+* Timeout exceptions extend from `SomeAsyncException`
6+
17## 3.2.9
28
39* Fixing a space leak. [#586] https://github.com/yesodweb/wai/pull/586
warp/Network/Wai/Handler/Warp/Run.hs+4−2
@@ -64,7 +64,8 @@ socketConnection s = do
6464 connSendMany = Sock.sendMany s
6565 , connSendAll = sendall
6666 , connSendFile = sendFile s writeBuf bufferSize sendall
67− , connClose = close s >> freeBuffer writeBuf
67+ , connClose = close s
68+ , connFree = freeBuffer writeBuf
6869 , connRecv = receive s bufferPool
6970 , connRecvBuf = receiveBuf s
7071 , connWriteBuffer = writeBuf
@@ -277,7 +278,8 @@ fork set mkConn addr app counter ii0 = settingsFork set $ \ unmask ->
277278 -- We grab the connection before registering timeouts since the
278279 -- timeouts will be useless during connection creation, due to the
279280 -- fact that async exceptions are still masked.
280− bracket mkConn (closeConn ref . fst) $ \(conn, transport) ->
281+ bracket mkConn (\(conn, _) -> closeConn ref conn `finally` connFree conn)
282+ $ \(conn, transport) ->
281283
282284 -- We need to register a timeout handler for this thread, and
283285 -- cancel that handler as soon as we exit. We additionally close
warp/Network/Wai/Handler/Warp/Types.hs+6−1
@@ -92,8 +92,13 @@ data Connection = Connection {
9292 , connSendAll :: ByteString -> IO ()
9393 -- | The sending function for files in HTTP/1.1.
9494 , connSendFile :: SendFile
95− -- | The connection closing function.
95+ -- | The connection closing function. Warp guarantees it will only be
96+ -- called once. Other functions (like 'connRecv') may be called after
97+ -- 'connClose' is called.
9698 , connClose :: IO ()
99+ -- | Free any buffers allocated. Warp guarantees it will only be
100+ -- called once, and no other functions will be called after it.
101+ , connFree :: IO ()
97102 -- | The connection receiving function. This returns "" for EOF.
98103 , connRecv :: Recv
99104 -- | The connection receiving function. This tries to fill the buffer.
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 3.2.9
2+Version: 3.2.10
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE