[Haskell-cafe] Space leak with recursion

Martijn Rijkeboer haskell at bunix.org
Fri Apr 24 08:41:30 UTC 2015


>> >> 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.

Will do.


>> > 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.

The state contains a sequence number that needs to be incremented,
but I left that out for brevity...

Kind regards,


Martijn Rijkeboer



More information about the Haskell-Cafe mailing list