From 4507c9d439399cf1f3c758ad7d90664c43d1ed83 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Sun, 28 Jul 2024 13:27:27 -0700 Subject: [PATCH] Refine exception handling in the filter_SDP(), reference nested SDP callback weakly, so that rtpproxy session can be destroyed on disconnect. --- sippy/b2bua_radius.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sippy/b2bua_radius.py b/sippy/b2bua_radius.py index 0efaf0a..dfb087a 100755 --- a/sippy/b2bua_radius.py +++ b/sippy/b2bua_radius.py @@ -29,6 +29,7 @@ import sys from functools import partial from os.path import dirname, join as p_join +from weakref import ref as weakref_ref sys.path.append(p_join(dirname(sys.argv[0]), '..')) from sippy.Core.EventDispatcher import ED2 @@ -154,13 +155,16 @@ def __init__(self, remote_ip, source, req_source, req_target, global_config, pas self.uaA.on_remote_sdp_change = self.filter_SDP def filter_SDP(self, body, done_cb, prev_orc = None): + if prev_orc is not None and (prev_orc:=prev_orc()) is None: + return try: body.parse() - except Exception as ex: - exx = SdpParseError(f'{ex}') - exx.msg = 'Malformed SDP body' - exx.code = 400 - raise exx from ex + except Exception as exception: + is_spe = isinstance(exception, SdpParseError) + if not is_spe: + dump_exception('can\'t parse SDP body', extra = body.content) + result_callback(None, ex=exception) + return allowed_pts = self.global_config['_allowed_pts'] for sect in body.content.sections: mbody = sect.m_header @@ -170,7 +174,8 @@ def filter_SDP(self, body, done_cb, prev_orc = None): _allowed_pts = [x if isinstance(x, int) else sect.getPTbyName(x) for x in allowed_pts] mbody.formats = [x for x in mbody.formats if x in _allowed_pts] if len(mbody.formats) == 0: - raise SdpParseError() + result_callback(None, ex=SdpParseError()) + return if old_len > len(mbody.formats): sect.optimize_a() if prev_orc is not None: @@ -349,6 +354,8 @@ def placeOriginate(self, oroute): self.proxied = True if '_allowed_pts' in self.global_config: prev_orc = self.uaO.on_remote_sdp_change + if prev_orc is not None: + prev_orc = weakref_ref(prev_orc) self.uaO.on_remote_sdp_change = partial(self.filter_SDP, prev_orc=prev_orc) self.uaO.kaInterval = self.global_config['keepalive_orig'] if 'group_timeout' in oroute.params: