fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/39556?usp=email )
Change subject: s1ap_proxy: catch exceptions in handle_pdu/2 ......................................................................
s1ap_proxy: catch exceptions in handle_pdu/2
We do have a try-catch block in handle_pdu_bin/2 that does catch exceptions happening in decode_pdu/1, but does not catch anything else. For instance, if something goes wrong in handle_pdu/2, the whole process will be terminated, among with all the linked E-RAB FSMs. This should definitely be avoided.
Change-Id: Ib1e6674f5b85557866c7beaea710ea903e4eeaca --- M src/s1ap_proxy.erl 1 file changed, 7 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/56/39556/1
diff --git a/src/s1ap_proxy.erl b/src/s1ap_proxy.erl index 56e5dee..0cef81e 100644 --- a/src/s1ap_proxy.erl +++ b/src/s1ap_proxy.erl @@ -215,7 +215,7 @@ try decode_pdu(OrigData) of {ok, PDU} -> ?LOG_DEBUG("Rx S1AP PDU: ~p", [PDU]), - case handle_pdu(PDU, S0) of + try handle_pdu(PDU, S0) of {{Action, NewPDU}, S1} -> {ok, NewData} = encode_pdu(NewPDU), ?LOG_DEBUG("Tx (~p) S1AP PDU: ~p", [Action, NewPDU]), @@ -232,6 +232,12 @@ s1gw_metrics:ctr_inc(?S1GW_CTR_S1AP_PROXY_OUT_PKT_FWD_ALL), s1gw_metrics:ctr_inc(?S1GW_CTR_S1AP_PROXY_OUT_PKT_FWD_UNMODIFIED), {{forward, OrigData}, S1} + catch + Exception:Reason:StackTrace -> + ?LOG_ERROR("An exception occurred: ~p, ~p, ~p", [Exception, Reason, StackTrace]), + s1gw_metrics:ctr_inc(?S1GW_CTR_S1AP_PROXY_EXCEPTION), + s1gw_metrics:ctr_inc(?S1GW_CTR_S1AP_PROXY_OUT_PKT_FWD_UNMODIFIED), + {{forward, OrigData}, S0} %% XXX: proxy as-is or drop? end; {error, {asn1, Error}} -> ?LOG_ERROR("S1AP PDU decoding failed: ~p", [Error]),