@@ -59,12 +59,37 @@ function _M:_get_next_id()
59
59
end
60
60
61
61
62
+ function _M :_report_error (payload_id , code , err )
63
+ local res , rpc_err = self .outgoing :push (
64
+ new_error (payload_id , code , err )
65
+ )
66
+
67
+ if not res then
68
+ ngx_log (ngx_WARN , " [rpc] unable to push RPC call error: " , rpc_err )
69
+ end
70
+ end
71
+
72
+
62
73
function _M ._dispatch (premature , self , cb , payload )
63
74
if premature then
64
75
return
65
76
end
66
77
67
- local res , err = cb (self .node_id , unpack (payload .params ))
78
+ local res , except , err , trace
79
+ xpcall (
80
+ function () res , err = cb (self .node_id , unpack (payload .params )) end ,
81
+ function (err )
82
+ except = err
83
+ trace = debug.traceback (nil , 2 )
84
+ end
85
+ )
86
+
87
+ if except then
88
+ ngx_log (ngx_WARN , " [rpc] exception during callback: " , except , " \n " , trace )
89
+
90
+ return self :_report_error (payload .id , jsonrpc .INTERNAL_ERROR , except )
91
+ end
92
+
68
93
if not res then
69
94
ngx_log (ngx_WARN , " [rpc] RPC callback failed: " , err )
70
95
@@ -73,13 +98,7 @@ function _M._dispatch(premature, self, cb, payload)
73
98
return
74
99
end
75
100
76
- res , err = self .outgoing :push (new_error (payload .id , jsonrpc .SERVER_ERROR ,
77
- err ))
78
- if not res then
79
- ngx_log (ngx_WARN , " [rpc] unable to push RPC call error: " , err )
80
- end
81
-
82
- return
101
+ return self :_report_error (payload .id , jsonrpc .SERVER_ERROR , err )
83
102
end
84
103
85
104
-- notification has no response
0 commit comments