Skip to content

Commit

Permalink
websocket worker now uses http in dire situations
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgios Kaissis committed Sep 21, 2020
1 parent 78e069a commit 5418699
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions syft/grid/clients/data_centric_fl_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,34 @@ def _forward_to_websocket_server_worker(self, message: bin) -> bin:
except TypeError:
response = serialize(None)
else:
self.ws.send_binary(message)
response = self.ws.recv()
try:
self.ws.send_binary(message)
response = self.ws.recv()
except Exception as e:
decoded_message = message.decode(self.encoding)
message = {
"encoding": self.encoding,
"payload": decoded_message,
}
url = self.address.replace("ws", "http") + "/data-centric/syft/"
# Multipart encoding
form = MultipartEncoder(message)
upload_size = form.len
monitor = MultipartEncoderMonitor(form, None)
headers = {
"Prefer": "respond-async",
"Content-Type": monitor.content_type,
}
try:
session = requests.Session()
response = session.post(url, headers=headers, data=monitor).content
session.close()
response = json.loads(response)["payload"]
response = response.encode(self.encoding)
except TypeError:
response = serialize(None)
finally:
url = self.address.replace("http", "ws") + "/data-centric/syft/"
return response

def _return_bool_result(self, result, return_key=None):
Expand Down

0 comments on commit 5418699

Please sign in to comment.