[Haskell-cafe] Space leak with recursion

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Apr 24 08:36:28 UTC 2015


On Fri, Apr 24, 2015 at 10:34:04AM +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.
> 
> This could be an issue, but during my testing there were no messages sent
> to the snapshot socket (I haven't implemented the snapshot socket in the
> client yet).

Then I suggest the first thing to try is to run a test without snapshot
socket functionality at all, and see if you still get a space leak.

> > It seems unwise to make a recursive call to the event loop inside a
> > handler.
> 
> How would I update my state and ensure that the next invocation of a
> handler gets the updated state? With the forever function my state updates
> are not propagated.

I don't see where you are updating any state.

Tom


More information about the Haskell-Cafe mailing list