vanzin closed pull request #23113: [SPARK-26019][PYTHON] Fix race condition in
accumulators.py: _start_update_server()
URL: https://github.com/apache/spark/pull/23113
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/pyspark/accumulators.py b/python/pyspark/accumulators.py
index 00ec094e7e3b4..5023fd3fd968c 100644
--- a/python/pyspark/accumulators.py
+++ b/python/pyspark/accumulators.py
@@ -271,8 +271,17 @@ def authenticate_and_accum_updates():
class AccumulatorServer(SocketServer.TCPServer):
def __init__(self, server_address, RequestHandlerClass, auth_token):
- SocketServer.TCPServer.__init__(self, server_address,
RequestHandlerClass)
self.auth_token = auth_token
+ SocketServer.TCPServer.__init__(self, server_address,
RequestHandlerClass, bind_and_activate=False)
+
+ def bind_and_serve(self):
+ try:
+ self.server_bind()
+ self.server_activate()
+ self.serve_forever()
+ except:
+ self.shutdown()
+ raise
"""
A simple TCP server that intercepts shutdown() in order to interrupt
@@ -289,7 +298,7 @@ def shutdown(self):
def _start_update_server(auth_token):
"""Start a TCP server to receive accumulator updates in a daemon thread,
and returns it"""
server = AccumulatorServer(("localhost", 0), _UpdateRequestHandler,
auth_token)
- thread = threading.Thread(target=server.serve_forever)
+ thread = threading.Thread(target=server.bind_and_serve)
thread.daemon = True
thread.start()
return server
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]