1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 01:47:01 +03:00

Gracefully close stat client socket

This commit is contained in:
Timothy Clem 2017-10-10 11:43:10 -07:00
parent aed26cdb52
commit 195c8174c9
2 changed files with 7 additions and 1 deletions

View File

@ -14,6 +14,7 @@ module Semantic.Stat
-- Client -- Client
, defaultStatsClient , defaultStatsClient
, StatsClient(..) , StatsClient(..)
, closeStatClient
-- Internal, exposed for testing -- Internal, exposed for testing
, renderDatagram , renderDatagram
@ -26,7 +27,7 @@ import Data.List (intercalate)
import Data.List.Split (splitOneOf) import Data.List.Split (splitOneOf)
import Data.Maybe import Data.Maybe
import Data.Monoid import Data.Monoid
import Network.Socket (Socket(..), SocketType(..), socket, connect, getAddrInfo, addrFamily, addrAddress, defaultProtocol) import Network.Socket (Socket(..), SocketType(..), socket, connect, close, getAddrInfo, addrFamily, addrAddress, defaultProtocol)
import Network.Socket.ByteString import Network.Socket.ByteString
import Network.URI import Network.URI
import Numeric import Numeric
@ -138,6 +139,10 @@ statsClient host port statsClientNamespace = do
connect sock (addrAddress addr) connect sock (addrAddress addr)
pure (StatsClient sock statsClientNamespace host port) pure (StatsClient sock statsClientNamespace host port)
-- | Close the client's underlying socket.
closeStatClient :: StatsClient -> IO ()
closeStatClient StatsClient{..} = close statsClientUDPSocket
-- | Send a stat over the StatsClient's socket. -- | Send a stat over the StatsClient's socket.
sendStat :: StatsClient -> Stat -> IO () sendStat :: StatsClient -> Stat -> IO ()
sendStat StatsClient{..} = void . tryIOError . sendAll statsClientUDPSocket . B.pack . renderDatagram statsClientNamespace sendStat StatsClient{..} = void . tryIOError . sendAll statsClientUDPSocket . B.pack . renderDatagram statsClientNamespace

View File

@ -162,6 +162,7 @@ runTaskWithOptions options task = do
run options logger statter task run options logger statter task
closeQueue statter closeQueue statter
closeStatClient (asyncQueueExtra statter)
closeQueue logger closeQueue logger
either (die . displayException) pure result either (die . displayException) pure result
where where