[Haskell-cafe] Space leak with recursion
Tom Ellis
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Apr 24 08:06:34 UTC 2015
On Thu, Apr 23, 2015 at 07:27:08PM +0200, Martijn Rijkeboer wrote:
> pollSockets :: State -> IO ()
> pollSockets state =
> void $ poll (-1)
> [ Sock (listenSocket state) [In] (Just $ observerHandleEvts state)
> , Sock (snapSocket state) [In] (Just $ snapshotHandleEvts state)
> ]
>
>
> observerHandleEvts :: State -> [Event] -> IO ()
> observerHandleEvts state _ = do
> void $ receiveMulti $ listenSocket state
> pollSockets state
>
>
> snapshotHandleEvts :: State -> [Event] -> IO ()
> snapshotHandleEvts state _ = do
> void $ receiveMulti $ snapSocket state
> pollSockets state
What happens here if there is an event waiting on both the listen socket
*and* the snap socket? It looks like `observerHandleEvts` will be called
and, since it recursively calles `pollSockets`, the `snapshotHandleEvts`
handler will not be run, although its continuation will be kept around
leaking space.
It seems unwise to make a recursive call to the event loop inside a handler.
Tom
More information about the Haskell-Cafe
mailing list