Test and migration TCP LB for non-Windows platforms.
Description of Issue/Question
We need to take a look at https://github.com/saltstack/salt/pull/32401 and see if it will work correctly on non-Windows platforms.
It will probably work as-is in Python 3 for non-Windows platforms (assuming you adjust the conditions for when USE_LOAD_BALANCER is set to True).
For Python 2 support, you will need code that looks like this:
from multiprocessing.reduction import reduce_handle
from multiprocessing.reduction import rebuild_handle
In LoadBalancerServer.run:
connection, address = self._socket.accept()
h = reduce_handle(connection.fileno())
# Wait for a free slot to be available to put
# the connection into.
self.socket_queue.put((h, address), True, None)
In LoadBalancerWorker.socket_queue_thread:
h, address = self.socket_queue.get(True, None)
fd = rebuild_handle(h)
client_socket = socket.fromfd(
fd, socket.AF_INET, socket.SOCK_STREAM
)
# 'self.io_loop' initialized in super class
# 'tornado.tcpserver.TCPServer'.
# 'self._handle_connection' defined in same super class.
self.io_loop.spawn_callback(
self._handle_connection, client_socket, address
)
The code for Python 2 and Python 3 are probably going to need to be different, because I don't think the socket is directly picklable in Python 2 even on non-Windows. If it is, then the Python 3 solution would work. And I know Python 3 removed reduce_handle and rebuild_handle (probably because sockets are now directly picklable). The problem with Python 2 on Windows is that socket.fromfd() isn't supported in Python 2 on Windows. That is why I couldn't come up with a good PY2 Windows solution. This shouldn't be a barrier on non-Windows platforms though.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.