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

Make GRPC transport decorators configurable & disable atomic decorator by default #1388

Merged
merged 4 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions openfl-workspace/workspace/plan/defaults/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ settings:
client_reconnect_interval : 5
require_client_auth : True
cert_folder : cert
enable_atomic_connections : False
16 changes: 13 additions & 3 deletions openfl/transport/grpc/aggregator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def intercept_stream_unary(self, continuation, client_call_details, request_iter

def _atomic_connection(func):
def wrapper(self, *args, **kwargs):
if not self.enable_atomic_connections:
return func(self, *args, **kwargs)
self.reconnect()
response = func(self, *args, **kwargs)
self.disconnect()
Expand All @@ -145,6 +147,8 @@ def wrapper(self, *args, **kwargs):

def _resend_data_on_reconnection(func):
def wrapper(self, *args, **kwargs):
if not self.resend_data_on_reconnection:
return func(self, *args, **kwargs)
while True:
try:
response = func(self, *args, **kwargs)
Expand Down Expand Up @@ -198,6 +202,8 @@ def __init__(
federation_uuid=None,
single_col_cert_common_name=None,
refetch_server_cert_callback=None,
enable_atomic_connections=False,
resend_data_on_reconnection=True,
**kwargs,
):
"""
Expand Down Expand Up @@ -228,9 +234,13 @@ def __init__(
self.certificate = certificate
self.private_key = private_key
self.sleeping_policy = ConstantBackoff(
int(kwargs.get("client_reconnect_interval", 1)), getLogger(__name__), self.uri
int(kwargs.get("client_reconnect_interval", 1)),
getLogger(__name__),
self.uri,
)
self.logger = getLogger(__name__)
self.enable_atomic_connections = enable_atomic_connections
self.resend_data_on_reconnection = resend_data_on_reconnection

if not self.use_tls:
self.logger.warning("gRPC is running on insecure channel with TLS disabled.")
Expand Down Expand Up @@ -345,7 +355,7 @@ def validate_response(self, reply, collaborator_name):

def disconnect(self):
"""Close the gRPC channel."""
self.logger.debug("Disconnecting from gRPC server at %s", self.uri)
self.logger.info("Disconnecting from gRPC server at %s", self.uri)
self.channel.close()

def reconnect(self):
Expand All @@ -365,7 +375,7 @@ def reconnect(self):
self.private_key,
)

self.logger.debug("Connecting to gRPC at %s", self.uri)
self.logger.info("Connecting to gRPC at %s", self.uri)

self.stub = aggregator_pb2_grpc.AggregatorStub(self.channel)

Expand Down
Loading