better handling of content not available from cluster

Sending ERROR caused the client to get confused and protocol to freeze.
Better to send empty DATA and indicate it's not valid.

This fixes a hang in git-annex testremote of a cluster accessed via the
http server. That testremote is still failing, for some reason after
storing a test key, the cluster reports it as not present.
This commit is contained in:
Joey Hess 2024-07-28 11:09:07 -04:00
parent fbbedae497
commit 4304f1b6ae
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -276,10 +276,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
handleGETTIMESTAMP remotesides
GET _ _ k -> proxyGET (proxySelector proxyparams) k >>= \case
Just remoteside -> handleGET remoteside requestmessage
Nothing ->
protoerrhandler requestcomplete $
client $ net $ sendMessage $
ERROR "content not present"
Nothing -> handleGETNoRemoteSide
PUT paf k -> do
af <- getassociatedfile paf
remotesides <- proxyPUT (proxySelector proxyparams) af k
@ -352,7 +349,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
-- Read a message from one party, send it to the other,
-- and then pass the message to the continuation.
relayonemessage from to cont =
flip protoerrhandler (from $ net $ receiveMessage) $
flip protoerrhandler (from $ net receiveMessage) $
withresp $ \message ->
protoerrhandler (cont message) $
to $ net $ sendMessage message
@ -460,6 +457,15 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
[] -> FAILURE
(err:_) -> ERROR err
else FAILURE_PLUS us
-- Send an empty DATA and indicate it was invalid.
handleGETNoRemoteSide = protoerrhandler requestcomplete $
client $ net $ do
sendMessage $ DATA (Len 0)
sendBytes (Len 0) mempty nullMeterUpdate
when (proxyClientProtocolVersion proxyparams /= ProtocolVersion 0) $
sendMessage (VALIDITY Invalid)
void $ receiveMessage
handleGET remoteside message = getresponse (runRemoteSide remoteside) message $
withDATA (relayGET remoteside) $ \case
@ -622,7 +628,7 @@ proxyRequest proxydone proxyparams requestcomplete requestmessage protoerrhandle
| proxyClientProtocolVersion proxyparams == ProtocolVersion 0 =
finish $ net receiveMessage
| otherwise =
flip protoerrhandler (client $ net $ receiveMessage) $
flip protoerrhandler (client $ net receiveMessage) $
withresp $ \message ->
finish $ do
-- Relay VALID or INVALID message