Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tcpclient doesn't close sockets #1

Open
chiller opened this issue Jul 6, 2017 · 1 comment
Open

Tcpclient doesn't close sockets #1

chiller opened this issue Jul 6, 2017 · 1 comment

Comments

@chiller
Copy link

chiller commented Jul 6, 2017

even though the connect documentation says that The connection socket is closed when done or in case of exceptions. this doesn't seem to happen with the tcpclient.

Here is code I used to reproduce based on the code in Readme.md:

module Main where

import           Data.Function
import qualified Network.Monitoring.Riemann.Event as Event
import           Network.Monitoring.Riemann.TCP
import           Network.Monitoring.Riemann.Client
import           Network.Monitoring.Riemann.TCPClient
import           Control.Concurrent

main :: IO ()
main = doSend

doSend = do
    c <- tcpClient "localhost" 5555
    putStrLn "doing some IO work"
    event <- pure $
                 Event.ok "my service"
                     & Event.description "my description"
                     & Event.metric (length [ "some data" ])
                     & Event.ttl 20
                     & Event.tags [ "tag1", "tag2" ]
    sendEvent c event
    putStrLn "do somethign else"
    event <- pure $ Event.ok "my other service"
    sendEvent c event
    putStrLn "finished"
    threadDelay 1000
    close c
    doSend

This exits after a while with the error simple-exe: Network.Socket.getAddrInfo: does not exist (System error) because there are too many open sockets (I checked with lsof -i ).

I'd be glad to fix this myself given some guidance.

@enzoh
Copy link

enzoh commented Nov 8, 2017

It's leaking connections for me as well.
Would be great to extend the API so that the connection can be closed.
Something like:

    let tcpOpen = tcpConnection host port
    bracket tcpOpen tcpClose $ \ connection -> do
        events <- blah blah blah
        sendEvents connection events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants