summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-21 00:59:38 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-21 00:59:38 -0400
commitd78527c2f7b902827fdf204f536199963c78419c (patch)
tree1cb9b1837b3e6a144370d0895414a3de0098cdd4 /Assistant
parentc65c4fc5202c9f94ad5ecd4d6d6a138ad923232d (diff)
XMPP: Be better at responding to CanPush messages when busy with something else.
Observed: With 2 xmpp clients, one would sometimes stop responding to CanPush messages. Often it was in the middle of a receive-pack of its own (or was waiting for a failed one to time out). Now these are always immediately responded to, which is fine; the point of CanPush is to find out if there's another client out there that's interested in our push. Also, in queueNetPushMessage, queue push initiation messages when we're already running the side of the push they would initiate. Before, these messages were sent into the netMessagesPush channel, which was wrong. The xmpp send-pack and receive-pack code discarded such messages. This still doesn't make XMPP push 100% robust. In testing, I am seeing it sometimes try to run two send-packs, or two receive-packs at once to the same client (probably because the client sent two requests). Also, I'm seeing rather a lot of cases where it stalls out until it runs into the 120 second timeout and cancels a push. And finally, there seems to be a bug in runPush. I have logs that show it running its setup action, but never its cleanup action. How is this possible given its use of E.bracket? Either some exception is finding its way through, or the action somehow stalls forever. When this happens, one of the 2 clients stops syncing.
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/NetMessager.hs2
-rw-r--r--Assistant/Threads/XMPPClient.hs1
-rw-r--r--Assistant/Types/NetMessager.hs7
-rw-r--r--Assistant/XMPP/Git.hs13
4 files changed, 15 insertions, 8 deletions
diff --git a/Assistant/NetMessager.hs b/Assistant/NetMessager.hs
index 97d17af6e..fd320b00b 100644
--- a/Assistant/NetMessager.hs
+++ b/Assistant/NetMessager.hs
@@ -110,8 +110,8 @@ queueNetPushMessage m@(Pushing clientid stage) = do
case v of
Nothing -> return False
(Just runningclientid)
- | runningclientid == clientid -> queue nm
| isPushInitiation stage -> defer nm
+ | runningclientid == clientid -> queue nm
| otherwise -> discard
where
side = pushDestinationSide stage
diff --git a/Assistant/Threads/XMPPClient.hs b/Assistant/Threads/XMPPClient.hs
index 086494a74..dd1b2ac1f 100644
--- a/Assistant/Threads/XMPPClient.hs
+++ b/Assistant/Threads/XMPPClient.hs
@@ -107,6 +107,7 @@ xmppClient urlrenderer d creds =
handle selfjid (GotNetMessage (PairingNotification stage c u)) =
maybe noop (inAssistant . pairMsgReceived urlrenderer stage u selfjid) (parseJID c)
handle _ (GotNetMessage m@(Pushing _ pushstage))
+ | isPushNotice pushstage = inAssistant $ handlePushNotice m
| isPushInitiation pushstage = inAssistant $
unlessM (queueNetPushMessage m) $ do
let checker = checkCloudRepos urlrenderer
diff --git a/Assistant/Types/NetMessager.hs b/Assistant/Types/NetMessager.hs
index 09a558033..bc0bf3c22 100644
--- a/Assistant/Types/NetMessager.hs
+++ b/Assistant/Types/NetMessager.hs
@@ -85,13 +85,16 @@ logClientID c = T.concat [T.take 1 c, T.pack $ show $ T.length c]
{- Things that initiate either side of a push, but do not actually send data. -}
isPushInitiation :: PushStage -> Bool
-isPushInitiation (CanPush _) = True
isPushInitiation (PushRequest _) = True
isPushInitiation (StartingPush _) = True
isPushInitiation _ = False
+isPushNotice :: PushStage -> Bool
+isPushNotice (CanPush _) = True
+isPushNotice _ = False
+
data PushSide = SendPack | ReceivePack
- deriving (Eq, Ord)
+ deriving (Eq, Ord, Show)
pushDestinationSide :: PushStage -> PushSide
pushDestinationSide (CanPush _) = ReceivePack
diff --git a/Assistant/XMPP/Git.hs b/Assistant/XMPP/Git.hs
index 93479014d..7970f0506 100644
--- a/Assistant/XMPP/Git.hs
+++ b/Assistant/XMPP/Git.hs
@@ -287,10 +287,6 @@ xmppRemotes cid theiruuid = case baseJID <$> parseJID cid of
knownuuid um r = Remote.uuid r == theiruuid || M.member theiruuid um
handlePushInitiation :: (Remote -> Assistant ()) -> NetMessage -> Assistant ()
-handlePushInitiation _ (Pushing cid (CanPush theiruuid)) =
- unlessM (null <$> xmppRemotes cid theiruuid) $ do
- u <- liftAnnex getUUID
- sendNetMessage $ Pushing cid (PushRequest u)
handlePushInitiation checkcloudrepos (Pushing cid (PushRequest theiruuid)) =
go =<< liftAnnex (inRepo Git.Branch.current)
where
@@ -317,8 +313,15 @@ handlePushInitiation checkcloudrepos (Pushing cid (StartingPush theiruuid)) = do
mapM_ checkcloudrepos rs
handlePushInitiation _ _ = noop
+handlePushNotice :: NetMessage -> Assistant ()
+handlePushNotice (Pushing cid (CanPush theiruuid)) =
+ unlessM (null <$> xmppRemotes cid theiruuid) $ do
+ u <- liftAnnex getUUID
+ sendNetMessage $ Pushing cid (PushRequest u)
+handlePushNotice _ = noop
+
handleDeferred :: (Remote -> Assistant ()) -> NetMessage -> Assistant ()
-handleDeferred = handlePushInitiation
+handleDeferred checkcloudrepos m = handlePushInitiation checkcloudrepos m
writeChunk :: Handle -> B.ByteString -> IO ()
writeChunk h b = do