Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Unified Diff: appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py

Issue 2755443002: Deep copy any proto values that might outlive the message (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py
diff --git a/appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py b/appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py
index 15a824670cc0ccc863ef3ab61142fae7286cf941..d12cffcf20095b31e02e0cfe0c0106d3381749b7 100644
--- a/appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py
+++ b/appengine/swarming/swarming_bot/bot_code/remote_client_grpc.py
@@ -5,6 +5,7 @@
# This is a reimplementation of RemoteClientNative but it uses (will use)
# a gRPC method to communicate with a server instead of REST.
+import copy
import json
import logging
import time
@@ -32,6 +33,10 @@ MAX_GRPC_SLEEP = 10.
class RemoteClientGrpc(object):
"""RemoteClientGrpc knows how to make calls via gRPC.
+
+ Any non-scalar value that is returned that references values from the proto
+ messages should be deepcopy'd since protos make use of weak references and
+ might be garbage-collected before the values are used.
"""
def __init__(self, server):
@@ -117,7 +122,7 @@ class RemoteClientGrpc(object):
},
}
logging.info('Completed handshake: %s', resp)
- return resp
+ return copy.deepcopy(resp)
def poll(self, attributes):
request = swarming_bot_pb2.PollRequest()
@@ -174,7 +179,7 @@ class RemoteClientGrpc(object):
}
logging.info('Received job manifest: %s', manifest)
self._log_is_asleep = False
- return 'run', manifest
+ return 'run', copy.deepcopy(manifest)
raise PollError('Unknown command in response: %s' % response)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698