[Haskell-cafe] Space leak with recursion

Martijn Rijkeboer haskell at bunix.org
Fri Apr 24 08:34:04 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).


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

Kind regards,


Martijn Rijkeboer




More information about the Haskell-Cafe mailing list