Skip to content

Commit b1c7bf3

Browse files
authored
[2.3] Changed exception log to error level for GRPC drivers (#2491)
* Changed exception log to error level * Use secure_format_exception
1 parent 9e02ba2 commit b1c7bf3

File tree

2 files changed

+27
-29
lines changed

2 files changed

+27
-29
lines changed

nvflare/fuel/f3/drivers/aio_grpc_driver.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def send_frame(self, frame: BytesAlike):
103103
f = Frame(seq=seq, data=bytes(frame))
104104
self.aio_ctx.run_coro(self.oq.put(f))
105105
except Exception as ex:
106-
self.logger.debug(f"exception send_frame: {self}: {secure_format_exception(ex)}")
106+
self.logger.error(f"exception send_frame: {self}: {secure_format_exception(ex)}")
107107
if not self.closing:
108108
raise CommError(CommError.ERROR, f"Error sending frame on conn {self}: {secure_format_exception(ex)}")
109109

@@ -121,14 +121,14 @@ async def read_loop(self, msg_iter):
121121
if error.code() == grpc.StatusCode.CANCELLED:
122122
self.logger.info(f"Connection {self} is closed by peer")
123123
else:
124-
self.logger.info(f"Connection {self} Error: {error.details()}")
125-
self.logger.debug(secure_format_traceback())
124+
self.logger.error(f"Connection {self} Error: {error.details()}")
125+
self.logger.error(secure_format_traceback())
126126
else:
127127
self.logger.info(f"Connection {self} is closed locally")
128128
except Exception as ex:
129129
if not self.closing:
130-
self.logger.info(f"{self}: exception {type(ex)} in read_loop: {secure_format_exception(ex)}")
131-
self.logger.debug(secure_format_traceback())
130+
self.logger.error(f"{self}: exception {type(ex)} in read_loop: {secure_format_exception(ex)}")
131+
self.logger.error(secure_format_traceback())
132132

133133
self.logger.info(f"{self}: in {ct.name}: done read_loop")
134134

@@ -141,10 +141,10 @@ async def generate_output(self):
141141
yield item
142142
except Exception as ex:
143143
if self.closing:
144-
self.logger.info(f"{self}: connection closed by {type(ex)}: {secure_format_exception(ex)}")
144+
self.logger.error(f"{self}: connection closed by {type(ex)}: {secure_format_exception(ex)}")
145145
else:
146-
self.logger.info(f"{self}: generate_output exception {type(ex)}: {secure_format_exception(ex)}")
147-
self.logger.debug(secure_format_traceback())
146+
self.logger.error(f"{self}: generate_output exception {type(ex)}: {secure_format_exception(ex)}")
147+
self.logger.error(secure_format_traceback())
148148
self.logger.debug(f"{self}: done generate_output")
149149

150150

@@ -183,9 +183,8 @@ async def Stream(self, request_iterator, context):
183183
except asyncio.CancelledError:
184184
self.logger.info("SERVER: RPC cancelled")
185185
except Exception as ex:
186-
if connection:
187-
self.logger.info(f"{connection}: connection exception: {secure_format_exception(ex)}")
188-
self.logger.debug(secure_format_traceback())
186+
self.logger.error(f"{connection}: connection exception: {secure_format_exception(ex)}")
187+
self.logger.error(secure_format_traceback())
189188
finally:
190189
if connection:
191190
connection.close()
@@ -221,7 +220,7 @@ def __init__(self, driver, connector, aio_ctx: AioContext, options, conn_ctx: _C
221220
self.logger.info(f"added insecure port at {addr}")
222221
except Exception as ex:
223222
conn_ctx.error = f"cannot listen on {addr}: {type(ex)}: {secure_format_exception(ex)}"
224-
self.logger.debug(conn_ctx.error)
223+
self.logger.error(conn_ctx.error)
225224

226225
async def start(self, conn_ctx: _ConnCtx):
227226
self.logger.debug("starting grpc server")
@@ -236,7 +235,7 @@ async def shutdown(self):
236235
try:
237236
await self.grpc_server.stop(grace=0.5)
238237
except Exception as ex:
239-
self.logger.debug(f"exception shutdown server: {secure_format_exception(ex)}")
238+
self.logger.error(f"exception shutdown server: {secure_format_exception(ex)}")
240239

241240

242241
class AioGrpcDriver(BaseDriver):
@@ -276,9 +275,11 @@ async def _start_server(self, connector: ConnectorInfo, aio_ctx: AioContext, con
276275
conn_ctx.conn = True
277276
await self.server.start(conn_ctx)
278277
except Exception as ex:
279-
if not self.closing:
280-
self.logger.debug(secure_format_traceback())
281278
conn_ctx.error = f"failed to start server: {type(ex)}: {secure_format_exception(ex)}"
279+
self.logger.error(conn_ctx.error)
280+
if not self.closing:
281+
self.logger.error(secure_format_traceback())
282+
282283
conn_ctx.waiter.set()
283284

284285
def listen(self, connector: ConnectorInfo):
@@ -327,14 +328,12 @@ async def _start_connect(self, connector: ConnectorInfo, aio_ctx: AioContext, co
327328
msg_iter = stub.Stream(connection.generate_output())
328329
conn_ctx.conn = connection
329330
await connection.read_loop(msg_iter)
330-
except asyncio.CancelledError:
331-
self.logger.debug("CLIENT: RPC cancelled")
332331
except grpc.FutureCancelledError:
333332
self.logger.info("CLIENT: Future cancelled")
334333
except Exception as ex:
335334
conn_ctx.error = f"connection {connection} error: {type(ex)}: {secure_format_exception(ex)}"
336-
self.logger.debug(conn_ctx.error)
337-
self.logger.debug(secure_format_traceback())
335+
self.logger.error(conn_ctx.error)
336+
self.logger.error(secure_format_traceback())
338337
finally:
339338
if connection:
340339
connection.close()

nvflare/fuel/f3/drivers/grpc_driver.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
add_StreamerServicer_to_server,
2929
)
3030
from nvflare.fuel.utils.obj_utils import get_logger
31-
from nvflare.security.logging import secure_format_exception
31+
from nvflare.security.logging import secure_format_exception, secure_format_traceback
3232

3333
from .base_driver import BaseDriver
3434
from .driver_params import DriverCap, DriverParams
@@ -69,15 +69,14 @@ def close(self):
6969
try:
7070
self.context.abort(grpc.StatusCode.CANCELLED, "service closed")
7171
except Exception as ex:
72-
# ignore any exception when aborting
73-
self.logger.debug(f"exception aborting GRPC context: {secure_format_exception(ex)}")
72+
self.logger.error(f"exception aborting GRPC context: {secure_format_exception(ex)}")
7473
self.context = None
7574
self.logger.info("Closed GRPC context")
7675
if self.channel:
7776
try:
7877
self.channel.close()
7978
except Exception as ex:
80-
self.logger.debug(f"exception closing GRPC channel: {secure_format_exception(ex)}")
79+
self.logger.error(f"exception closing GRPC channel: {secure_format_exception(ex)}")
8180
self.channel = None
8281
self.logger.info("Closed GRPC Channel")
8382

@@ -88,7 +87,7 @@ def send_frame(self, frame: Union[bytes, bytearray, memoryview]):
8887
self.logger.debug(f"{self.side}: queued frame #{seq}")
8988
self.oq.append(Frame(seq=seq, data=bytes(frame)))
9089
except BaseException as ex:
91-
raise CommError(CommError.ERROR, f"Error sending frame: {ex}")
90+
raise CommError(CommError.ERROR, f"Error sending frame: {secure_format_exception(ex)}")
9291

9392
def read_loop(self, msg_iter):
9493
ct = threading.current_thread()
@@ -106,7 +105,9 @@ def read_loop(self, msg_iter):
106105
self.logger.error(f"{self.side}: Frame receiver not registered for connection: {self.name}")
107106
except Exception as ex:
108107
if not self.closing:
109-
self.logger.debug(f"{self.side}: exception {type(ex)} in read_loop")
108+
self.logger.error(f"{self}: exception {type(ex)} in read_loop: {secure_format_exception(ex)}")
109+
self.logger.debug(secure_format_traceback())
110+
110111
if self.oq:
111112
self.logger.debug(f"{self.side}: closing queue")
112113
self.oq.close()
@@ -150,7 +151,7 @@ def Stream(self, request_iterator, context):
150151
t.start()
151152
yield from connection.generate_output()
152153
except BaseException as ex:
153-
self.logger.error(f"Connection closed due to error: {ex}")
154+
self.logger.error(f"Connection closed due to error: {secure_format_exception(ex)}")
154155
finally:
155156
if t is not None:
156157
t.join()
@@ -189,7 +190,7 @@ def __init__(
189190
self.logger.info(f"added insecure port at {addr}")
190191
except Exception as ex:
191192
error = f"cannot listen on {addr}: {type(ex)}: {secure_format_exception(ex)}"
192-
self.logger.debug(error)
193+
self.logger.error(error)
193194

194195
def start(self):
195196
self.grpc_server.start()
@@ -260,8 +261,6 @@ def connect(self, connector: ConnectorInfo):
260261
self.logger.debug("CLIENT: added connection")
261262
received = stub.Stream(connection.generate_output())
262263
connection.read_loop(received)
263-
except grpc.FutureCancelledError:
264-
self.logger.debug("RPC Cancelled")
265264
except Exception as ex:
266265
self.logger.error(f"connection {connection} error: {type(ex)}: {secure_format_exception(ex)}")
267266
finally:

0 commit comments

Comments
 (0)