From 135a6c6a5c2a611789f43887cc63daaa88255c85 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 14 Jul 2009 11:58:22 +0200
Subject: [PATCH] Introduce timeout in RAPI queries

The patch adds two constants in Types.hs for connect and query timeout,
then modifies Rapi.hs to use them as the connect and general curl
timeout.

Rapi could be improved more, as currently we wait double the total
timeout due to not aborting early in case the node queries failed.
---
 Ganeti/HTools/Rapi.hs  |  5 ++++-
 Ganeti/HTools/Types.hs | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs
index fc6a46cb7..4a06c029c 100644
--- a/Ganeti/HTools/Rapi.hs
+++ b/Ganeti/HTools/Rapi.hs
@@ -46,7 +46,10 @@ import qualified Ganeti.HTools.Instance as Instance
 getUrl :: (Monad m) => String -> IO (m String)
 getUrl url = do
   (code, body) <- curlGetString url [CurlSSLVerifyPeer False,
-                                     CurlSSLVerifyHost 0]
+                                     CurlSSLVerifyHost 0,
+                                     CurlTimeout (fromIntegral queryTimeout),
+                                     CurlConnectTimeout
+                                     (fromIntegral connTimeout)]
   return (case code of
             CurlOK -> return body
             _ -> fail $ printf "Curl error for '%s', error %s"
diff --git a/Ganeti/HTools/Types.hs b/Ganeti/HTools/Types.hs
index 4a009f449..8b082353f 100644
--- a/Ganeti/HTools/Types.hs
+++ b/Ganeti/HTools/Types.hs
@@ -32,6 +32,8 @@ module Ganeti.HTools.Types
     , FailMode(..)
     , FailStats
     , OpResult(..)
+    , connTimeout
+    , queryTimeout
     ) where
 
 -- | The instance index type.
@@ -43,6 +45,14 @@ type Ndx = Int
 -- | The type used to hold name-to-idx mappings.
 type NameAssoc = [(String, Int)]
 
+-- | Connection timeout (when using non-file methods).
+connTimeout :: Int
+connTimeout = 15
+
+-- | The default timeout for queries (when using non-file methods).
+queryTimeout :: Int
+queryTimeout = 60
+
 {-|
 
 This is similar to the JSON library Result type - *very* similar, but
-- 
GitLab