Pysyft client and server

443 views Asked by At

This question is with regards to my project on federated learning using the pysyft library, but those with the knowledge of websockets can help too since pysyft uses websockets for the server and client interaction.

To start off, i have an issue regarding server and client interaction. I have created a dashboard to launch a pysyft server and a pysyft client which connects to the aforementioned server. However, i have a scenario where i want to have the client disconnect from the server from time to time (manual disconnection) so as to perform changes in model parameters.

My solution was to perform a close() on the pysyft websocketClientWorker which calls the shutdown() function on the websocket object. Doing which, i presume, will close the connection between the client and the server. After whatever changes to the model parameters have been done. I will recreate the pysyft websocketClientWorker object again and perform the model training all over again. However, i am faced with the issue of : websocket._exceptions.WebSocketConnectionClosedException: socket is already closed. This exception is being thrown (despite the successful connection to the server) during the iteration of the dataloader.

Perhaps there's a better way to go about this scenario, or am i missing certain fundamental understanding of websockets. Any help will be appreciated. Thank you :)

1

There are 1 answers

0
Seph On

I managed to find the solution to my question after days of thorough inspection of the pysyft library. Turns out there is no issue with the Websocket connection and re-connection. Apparently, the superclass of websocketclient (baseworker) contains a worker registry which caches the websocketclient objects when the auto_add variable is set to True. This registry is indexed by the websocketclient ID and thus, recreation of the websocketclient object will not get replaced in the registry if the ID is the same. Therefore, this explains the 'socket is already closed' issue since it's referencing to the previous websocketclient connection that I have closed. The solution was to simply call the remove_worker_from_local_worker_registry() method on the websocketclient object before closing its connection.