eRPC: Server closes connection on exception to prevent client to block until timeout when it happens.
authorEdouard Tisserant <edouard@beremiz.fr>
Mon, 28 Oct 2024 16:06:50 +0100
changeset 4033 208a808d1081
parent 4032 1ffff67678ad
child 4034 6359536d60a9
eRPC: Server closes connection on exception to prevent client to block until timeout when it happens.
runtime/eRPCServer.py
--- a/runtime/eRPCServer.py	Mon Oct 28 16:02:47 2024 +0100
+++ b/runtime/eRPCServer.py	Mon Oct 28 16:06:50 2024 +0100
@@ -60,7 +60,7 @@
         lambda orders : ([(order.idx, None if len(order.force)==0 else bytes(order.force)) for order in orders],)
 }
 
-def rpc_wrapper(method_name):
+def rpc_wrapper(method_name, server):
     PLCobj = PLC()
     method=getattr(PLCobj, method_name)
     args_wrapper = ArgsWrappers.get(method_name, lambda *x:x)
@@ -73,7 +73,8 @@
             return 0
         except Exception as e:
             print(traceback.format_exc())
-            PLCobj.LogMessage(CRITICAL_LOG_LEVEL, f'eRPC call {method_name} Exception "{str(e)}"')
+            PLCobj.LogMessage(LogLevelsDict["CRITICAL"], f'eRPC call {method_name} Exception "{str(e)}"')
+            server.transport.close()
             raise
         
     return exception_wrapper
@@ -110,7 +111,7 @@
         handler = type(
             "PLCObjectServiceHandlder", 
             (IBeremizPLCObjectService,),
-            {name: rpc_wrapper(name)              
+            {name: rpc_wrapper(name, self)
                     for name,_func in getmembers(IBeremizPLCObjectService, isfunction)})()
         
         service = BeremizPLCObjectServiceService(handler)