Commit ee2b2eda authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Fix file descriptor leak in Confd Client

The queryOneServer function opens a UDP socket to connect
to the specified confd server. However, it would never
close it. Fix this and do so in a bracket construction
to make sure it also gets cleaned up in case of errors.
Signed-off-by: default avatarKlaus Aehlig <>
Reviewed-by: default avatarPetr Pudlak <>
parent 25fe44b7
......@@ -29,6 +29,7 @@ module Ganeti.Confd.Client
) where
import Control.Concurrent
import Control.Exception (bracket)
import Control.Monad
import Data.List
import Data.Maybe
......@@ -121,9 +122,10 @@ queryOneServer semaphore answer crType cQuery hmac (host, port) = do
addr <- resolveAddr (fromIntegral port) host
(af_family, sockaddr) <-
exitIfBad "Unable to resolve the IP address" addr
s <- S.socket af_family S.Datagram S.defaultProtocol
_ <- S.sendTo s completeMsg sockaddr
replyMsg <- S.recv s C.maxUdpDataSize
replyMsg <- bracket (S.socket af_family S.Datagram S.defaultProtocol) S.sClose
$ \s -> do
_ <- S.sendTo s completeMsg sockaddr
S.recv s C.maxUdpDataSize
parsedReply <-
if C.confdMagicFourcc `isPrefixOf` replyMsg
then return . parseReply hmac (drop 4 replyMsg) $ confdRqRsalt request
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment