Git Product home page Git Product logo

Comments (4)

bazukas avatar bazukas commented on September 24, 2024

Hello, have you been able to replicate? Saw this today, maybe this is connected?
http://www.well-typed.com/blog/2016/09/sharing-conduit/

from irc-conduit.

barrucadu avatar barrucadu commented on September 24, 2024

I ran a simple IRC client that just connected to freenode and sat in #freenode for a couple of weeks, with a load of profiling options: hb, hc, hd, hm, hr, hy. It definitely looks like a memory leak.

That blog post looks like it might be related, as there's a leak of Pipe and ->Pipe types, which matches up. I need to dig into the code and see what I can find.

from irc-conduit.

barrucadu avatar barrucadu commented on September 24, 2024

A small change here and to irc-client seems to have improved this.

irc-client

This surprises me, but does seem to change the retainer profile:

--- a/Network/IRC/Client/Internal.hs
+++ b/Network/IRC/Client/Internal.hs
@@ -118,16 +118,17 @@ forgetful = awaitForever go where
 -- | Block on receiving a message and invoke all matching handlers
 -- concurrently.
 eventSink :: MonadIO m => IRCState s -> Consumer IrcEvent m ()
-eventSink ircstate = await >>= maybe (return ()) (\event -> do
-  let event'  = decodeUtf8 <$> event
-  ignored <- isIgnored ircstate event'
-  unless ignored $ do
-    handlers <- getHandlersFor event' . _eventHandlers <$> getInstanceConfig' ircstate
-    liftIO $ mapM_ (\h -> forkIO $ runReaderT (h event') ircstate) handlers                                                                                                                                           
-
-  -- If disconnected, do not loop.
-  disconnected <- (==Disconnected) <$> getConnState ircstate
-  unless disconnected (eventSink ircstate))
+eventSink ircstate = go where
+  go = await >>= maybe (return ()) (\event -> do
+    let event'  = decodeUtf8 <$> event
+    ignored <- isIgnored ircstate event'
+    unless ignored $ do
+      handlers <- getHandlersFor event' . _eventHandlers <$> getInstanceConfig' ircstate
+      liftIO $ mapM_ (\h -> forkIO $ runReaderT (h event') ircstate) handlers
+
+    -- If disconnected, do not loop.
+    disconnected <- (==Disconnected) <$> getConnState ircstate
+    unless disconnected go)

Profiles: hb, hc, hd, hm, hr (graph), hr (profile), hy.

irc-conduit

There's a large ARR_WORDS leak in the prior graphs, which suggests a ByteString leak, so I made the helper function in chunked stricter:

--- a/Network/IRC/Conduit/Internal/Conduits.hs
+++ b/Network/IRC/Conduit/Internal/Conduits.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE BangPatterns      #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE RankNTypes        #-}

@@ -7,7 +8,7 @@
 -- License     : MIT
 -- Maintainer  : Michael Walker <[email protected]>
 -- Stability   : experimental
--- Portability : OverloadedStrings, RankNTypes
+-- Portability : BangPatterns, OverloadedStrings, RankNTypes
 --
 -- Internal helper conduits. This module is NOT considered to form
 -- part of the public interface of this library.
@@ -25,7 +26,7 @@ import qualified Data.ByteString as B
 chunked :: Monad m => Conduit ByteString m ByteString
 chunked = chunked' ""
   where
-    chunked' leftover = do
+    chunked' !leftover = do
       -- Wait for a value from upstream
       val <- await

Profiles: hb, hc, hd, hm, hr (graph), hr (profile), hy.

from irc-conduit.

barrucadu avatar barrucadu commented on September 24, 2024

I think this is now fixed in the 0.2.1.1 release. The cause was exceptionalConduit leaking on every (whoops) received message. The release also has the stricter chunked, which should reduce the overall memory usage a bit too.

from irc-conduit.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.