Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set an auth key in multi_process_shared.py #26172

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sdks/python/apache_beam/utils/multi_process_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import fasteners

T = TypeVar('T')
AUTH_KEY = b'mps'


class _SingletonProxy:
Expand Down Expand Up @@ -202,7 +203,11 @@ def _get_manager(self):
address = fin.read()
logging.info('Connecting to remote proxy at %s', address)
host, port = address.split(':')
manager = _SingletonRegistrar(address=(host, int(port)))
# We need to be able to authenticate with both the manager and
# the process.
manager = _SingletonRegistrar(
address=(host, int(port)), authkey=AUTH_KEY)
multiprocessing.current_process().authkey = AUTH_KEY
try:
manager.connect()
self._manager = manager
Expand All @@ -224,7 +229,10 @@ def release(self, obj):
self._manager.release_singleton(self._tag, obj)

def _create_server(self, address_file):
self._serving_manager = _SingletonRegistrar(address=('localhost', 0))
# We need to be able to authenticate with both the manager and the process.
self._serving_manager = _SingletonRegistrar(
address=('localhost', 0), authkey=AUTH_KEY)
multiprocessing.current_process().authkey = AUTH_KEY
# Initialize eagerly to avoid acting as the server if there are issues.
# Note, however, that _create_server itself is called lazily.
_process_level_singleton_manager.register_singleton(
Expand Down