# HG changeset patch
# User Edouard Tisserant <edouard@beremiz.fr>
# Date 1730128010 -3600
# Node ID 208a808d1081385dff8d15f2030e72d28efe18dd
# Parent  1ffff67678adb3ec2d72111b96377e99cc3cf9b9
eRPC: Server closes connection on exception to prevent client to block until timeout when it happens.

diff -r 1ffff67678ad -r 208a808d1081 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)