FreeSWITCH 异常重启后会话快速恢复
FreeSWITCH 异常重启后会话快速恢复
配置
会话追踪
sip_profiles/*.xml
<param name="track-calls" value="true"/>
(官方文档描述会有轻微性能影响)
存储恢复数据、修改数据库位置
重要
fs默认使用sqlite进行恢复数据的存储,也可以正常使用,但此处改为odbc,使得数据易见。
autoload_configs/switch.conf.xml
<param name="core-db-dsn" value="odbc://dsn:用户名:密码"/>
本质是将会话信息存储到数据库,恢复时读取关键信息用以恢复。
表名:recovery
例:
表数据一览:

关键信息:
<cdr core-uuid="7f083c47-c818-44f4-97c7-17a7a1a09066" switchname="localhost.localdomain">
<channel_data>
<state>CS_CONSUME_MEDIA</state>
<direction>outbound</direction>
<state_number>7</state_number>
<flags>0=1;1=1;2=1;22=1;26=1;39=1;45=1;46=1;50=1;55=1;59=1;88=1;89=1;100=1;107=1;113=1;114=1;143=1;160=1;166=1</flags>
<caps>1=1;2=1;3=1;4=1;5=1;6=1;8=1;9=1;10=1</caps>
</channel_data>
<call-stats>
<audio>
<inbound>
<raw_bytes>0</raw_bytes>
<media_bytes>0</media_bytes>
<packet_count>0</packet_count>
<media_packet_count>0</media_packet_count>
<skip_packet_count>0</skip_packet_count>
<jitter_packet_count>0</jitter_packet_count>
<dtmf_packet_count>0</dtmf_packet_count>
<cng_packet_count>0</cng_packet_count>
<flush_packet_count>0</flush_packet_count>
<largest_jb_size>0</largest_jb_size>
<jitter_min_variance>0.00</jitter_min_variance>
<jitter_max_variance>0.00</jitter_max_variance>
<jitter_loss_rate>0.00</jitter_loss_rate>
<jitter_burst_rate>0.00</jitter_burst_rate>
<mean_interval>0.00</mean_interval>
<flaw_total>0</flaw_total>
<quality_percentage>100.00</quality_percentage>
<mos>4.50</mos>
</inbound>
<outbound>
<raw_bytes>0</raw_bytes>
<media_bytes>0</media_bytes>
<packet_count>0</packet_count>
<media_packet_count>0</media_packet_count>
<skip_packet_count>0</skip_packet_count>
<dtmf_packet_count>0</dtmf_packet_count>
<cng_packet_count>0</cng_packet_count>
<rtcp_packet_count>0</rtcp_packet_count>
<rtcp_octet_count>0</rtcp_octet_count>
</outbound>
</audio>
<video>
<inbound>
<raw_bytes>0</raw_bytes>
<media_bytes>0</media_bytes>
<packet_count>0</packet_count>
<media_packet_count>0</media_packet_count>
<skip_packet_count>1</skip_packet_count>
<jitter_packet_count>0</jitter_packet_count>
<dtmf_packet_count>0</dtmf_packet_count>
<cng_packet_count>0</cng_packet_count>
<flush_packet_count>0</flush_packet_count>
<largest_jb_size>0</largest_jb_size>
<jitter_min_variance>0.00</jitter_min_variance>
<jitter_max_variance>0.00</jitter_max_variance>
<jitter_loss_rate>0.00</jitter_loss_rate>
<jitter_burst_rate>0.00</jitter_burst_rate>
<mean_interval>0.00</mean_interval>
<flaw_total>0</flaw_total>
<quality_percentage>100.00</quality_percentage>
<mos>4.50</mos>
</inbound>
<outbound>
<raw_bytes>1030</raw_bytes>
<media_bytes>1030</media_bytes>
<packet_count>7</packet_count>
<media_packet_count>7</media_packet_count>
<skip_packet_count>0</skip_packet_count>
<dtmf_packet_count>0</dtmf_packet_count>
<cng_packet_count>0</cng_packet_count>
<rtcp_packet_count>0</rtcp_packet_count>
<rtcp_octet_count>0</rtcp_octet_count>
</outbound>
</video>
</call-stats>
<variables>
<direction>outbound</direction>
<is_outbound>true</is_outbound>
<uuid>8dc21c06-a91c-467a-88c5-fd0a5dafa406</uuid>
<session_id>5</session_id>
<sip_profile_name>internal-video</sip_profile_name>
<sip_destination_url>sip%3A990005%40192.168.4.18%3A55867%3Btransport%3Dudp%3Bfs_nat%3Dyes%3Bfs_path%3Dsip%3A990005%40192.168.4.18%3A55867%3Btransport%3Dudp</sip_destination_url>
<dialed_user>990005</dialed_user>
<dialed_domain>192.168.2.22</dialed_domain>
<sip_invite_domain>192.168.2.22</sip_invite_domain>
<presence_id>990005%40192.168.2.22</presence_id>
<sip_nat_detected>true</sip_nat_detected>
<sofia_profile_name>internal-video</sofia_profile_name>
<recovery_profile_name>internal-video</recovery_profile_name>
<sofia_profile_url>sip%3Amod_sofia%40192.168.2.22%3A5060</sofia_profile_url>
<endpoint_disposition>ANSWER</endpoint_disposition>
<record_stereo>true</record_stereo>
<default_gateway>example.com</default_gateway>
<default_areacode>918</default_areacode>
<transfer_fallback_extension>operator</transfer_fallback_extension>
<toll_allow>domestic,international,local</toll_allow>
<accountcode>990005</accountcode>
<user_context>default</user_context>
<outbound_caller_id_name>FreeSWITCH</outbound_caller_id_name>
<outbound_caller_id_number>0000000000</outbound_caller_id_number>
<callgroup>techsupport</callgroup>
<max_forwards>68</max_forwards>
<originator_video_codec>H264%4090000h%400i</originator_video_codec>
<originator_codec>G729%408000h%4020i,H264%4090000h%400i</originator_codec>
<originator>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</originator>
<export_vars>RFC2822_DATE</export_vars>
<RFC2822_DATE>Mon,%2024%20Mar%202025%2015%3A18%3A32%20%2B0800</RFC2822_DATE>
<originate_early_media>true</originate_early_media>
<originating_leg_uuid>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</originating_leg_uuid>
<originate_endpoint>user</originate_endpoint>
<recovered>true</recovered>
<sip_handle_full_from>%22990003%22%20%3Csip%3A990003%40192.168.2.22%3E%3Btag%3Da1ctQKmK945jS</sip_handle_full_from>
<sip_handle_full_to>%3Csip%3A990005%40192.168.4.18%3A55867%3Btransport%3Dudp%3E%3Btag%3DeFcJB51</sip_handle_full_to>
<video_media_flow>disabled</video_media_flow>
<text_media_flow>disabled</text_media_flow>
<channel_name>sofia/internal-video/990005%40192.168.4.18%3A55867</channel_name>
<sip_invite_call_id>8dc21c06-a91c-467a-88c5-fd0a5dafa406</sip_invite_call_id>
<sip_route_uri>sip%3A(null)%40192.168.4.18%3A55867</sip_route_uri>
<rtp_use_codec_name>G729</rtp_use_codec_name>
<rtp_use_codec_fmtp>annexb%3Dyes</rtp_use_codec_fmtp>
<rtp_use_codec_rate>8000</rtp_use_codec_rate>
<rtp_use_codec_ptime>20</rtp_use_codec_ptime>
<rtp_use_codec_channels>1</rtp_use_codec_channels>
<rtp_last_audio_codec_string>G729%408000h%4020i%401c</rtp_last_audio_codec_string>
<read_codec>G729</read_codec>
<original_read_codec>G729</original_read_codec>
<read_rate>8000</read_rate>
<original_read_rate>8000</original_read_rate>
<write_codec>G729</write_codec>
<write_rate>8000</write_rate>
<audio_media_flow>sendrecv</audio_media_flow>
<video_read_codec>H264</video_read_codec>
<video_read_rate>90000</video_read_rate>
<video_write_codec>H264</video_write_codec>
<video_write_rate>90000</video_write_rate>
<rtp_last_video_codec_string>H264%4090000h</rtp_last_video_codec_string>
<rtp_use_video_codec_name>H264</rtp_use_video_codec_name>
<rtp_use_video_codec_fmtp>profile-level-id%3D42801F</rtp_use_video_codec_fmtp>
<rtp_use_video_codec_rate>90000</rtp_use_video_codec_rate>
<rtp_use_video_codec_ptime>0</rtp_use_video_codec_ptime>
<local_media_ip>192.168.2.22</local_media_ip>
<local_media_port>16496</local_media_port>
<advertised_media_ip>192.168.2.22</advertised_media_ip>
<rtp_use_timer_name>soft</rtp_use_timer_name>
<rtp_use_pt>18</rtp_use_pt>
<rtp_use_ssrc>1476670368</rtp_use_ssrc>
<rtp_2833_send_payload>101</rtp_2833_send_payload>
<rtp_2833_recv_payload>101</rtp_2833_recv_payload>
<local_video_ip>192.168.2.22</local_video_ip>
<local_video_port>29646</local_video_port>
<rtp_use_video_pt>102</rtp_use_video_pt>
<rtp_use_video_ssrc>605291748</rtp_use_video_ssrc>
<rtp_local_sdp_str>v%3D0%0D%0Ao%3DFocustarCC%201742784243%201742784245%20IN%20IP4%20192.168.2.22%0D%0As%3DFocustarCC%0D%0Ac%3DIN%20IP4%20192.168.2.22%0D%0At%3D0%200%0D%0Am%3Daudio%2016496%20RTP/AVP%2018%20101%0D%0Aa%3Drtpmap%3A18%20G729/8000%0D%0Aa%3Dfmtp%3A18%20annexb%3Dno%0D%0Aa%3Drtpmap%3A101%20telephone-event/0%0D%0Aa%3Dfmtp%3A101%200-15%0D%0Aa%3Dptime%3A20%0D%0Aa%3Dsendrecv%0D%0Am%3Dvideo%2029646%20RTP/AVP%20102%0D%0Ab%3DAS%3A3072%0D%0Aa%3Drtpmap%3A102%20H264/90000%0D%0Aa%3Dfmtp%3A102%20profile-level-id%3D42801F%0D%0Aa%3Drtcp-fb%3A102%20ccm%20fir%0D%0Aa%3Drtcp-fb%3A102%20ccm%20tmmbr%0D%0Aa%3Drtcp-fb%3A102%20nack%0D%0Aa%3Drtcp-fb%3A102%20nack%20pli%0D%0A</rtp_local_sdp_str>
<sip_outgoing_contact_uri>%3Csip%3A990005%40192.168.2.22%3A5060%3E</sip_outgoing_contact_uri>
<sip_req_uri>990005%40192.168.4.18%3A55867%3Btransport%3Dudp</sip_req_uri>
<sip_local_network_addr>192.168.2.22</sip_local_network_addr>
<sip_reply_host>192.168.4.18</sip_reply_host>
<sip_reply_port>55867</sip_reply_port>
<sip_network_ip>192.168.4.18</sip_network_ip>
<sip_network_port>55867</sip_network_port>
<sip_user_agent>Linphone-Desktop/5.2.6%20(work)%20windows/10%20Qt/5.15.2%20LinphoneSDK/5.3.72</sip_user_agent>
<sip_allow>INVITE,%20ACK,%20CANCEL,%20OPTIONS,%20BYE,%20REFER,%20NOTIFY,%20MESSAGE,%20SUBSCRIBE,%20INFO,%20PRACK,%20UPDATE</sip_allow>
<sip_recover_contact>%3Csip%3A990005%40192.168.4.18%3A55867%3Btransport%3Dudp%3E%3Bexpires%3D60%3B%2Borg.linphone.specs%3D%22lime%22</sip_recover_contact>
<sip_full_via>SIP/2.0/UDP%20192.168.2.22%3Brport%3Bbranch%3Dz9hG4bKvZ89jcXZ9ejZH</sip_full_via>
<sip_recover_via>SIP/2.0/UDP%20192.168.2.22%3Brport%3Bbranch%3Dz9hG4bKvZ89jcXZ9ejZH</sip_recover_via>
<sip_from_display>990003</sip_from_display>
<sip_full_from>%22990003%22%20%3Csip%3A990003%40192.168.2.22%3E%3Btag%3Da1ctQKmK945jS</sip_full_from>
<sip_full_to>%3Csip%3A990005%40192.168.4.18%3A55867%3Btransport%3Dudp%3E%3Btag%3DeFcJB51</sip_full_to>
<sip_from_user>990003</sip_from_user>
<sip_from_uri>990003%40192.168.2.22</sip_from_uri>
<sip_from_host>192.168.2.22</sip_from_host>
<sip_to_params>transport%3Dudp</sip_to_params>
<sip_to_user>990005</sip_to_user>
<sip_to_port>55867</sip_to_port>
<sip_to_uri>990005%40192.168.4.18%3A55867</sip_to_uri>
<sip_to_host>192.168.4.18</sip_to_host>
<sip_contact_params>transport%3Dudp</sip_contact_params>
<sip_contact_user>990005</sip_contact_user>
<sip_contact_port>55867</sip_contact_port>
<sip_contact_uri>990005%40192.168.4.18%3A55867</sip_contact_uri>
<sip_contact_host>192.168.4.18</sip_contact_host>
<sip_to_tag>eFcJB51</sip_to_tag>
<sip_from_tag>a1ctQKmK945jS</sip_from_tag>
<sip_cseq>96846577</sip_cseq>
<sip_call_id>8dc21c06-a91c-467a-88c5-fd0a5dafa406</sip_call_id>
<switch_r_sdp>v%3D0%0D%0Ao%3D990005%203440%20498%20IN%20IP4%20172.16.100.124%0D%0As%3DTalk%0D%0Ac%3DIN%20IP4%20172.16.100.124%0D%0At%3D0%200%0D%0Am%3Daudio%207078%20RTP/AVP%2018%0D%0Aa%3Dfmtp%3A18%20annexb%3Dyes%0D%0Aa%3Dsendrecv%0D%0Am%3Dvideo%209078%20RTP/AVP%20102%0D%0Aa%3Drtpmap%3A102%20H264/90000%0D%0Aa%3Dfmtp%3A102%20profile-level-id%3D42801F%0D%0Aa%3Dsendrecv%0D%0Aa%3Drtcp-fb%3A*%20trr-int%201000%0D%0Aa%3Drtcp-fb%3A*%20nack%0D%0Aa%3Drtcp-fb%3A*%20ccm%20tmmbr%0D%0Aa%3Drtcp-fb%3A102%20nack%20pli%0D%0Aa%3Drtcp-fb%3A102%20ccm%20fir%0D%0A</switch_r_sdp>
<ep_codec_string>mod_bcg729.G729%408000h%4020i%408000b,mod_av.H264~profile-level-id%3D42801F</ep_codec_string>
<rtp_use_codec_string>G729%408000h%4020i,H264%4090000h%400i,PCMA,PCMU,G729,VP8,H264</rtp_use_codec_string>
<remote_text_media_flow>inactive</remote_text_media_flow>
<remote_audio_media_flow>sendrecv</remote_audio_media_flow>
<remote_media_ip>172.16.100.124</remote_media_ip>
<remote_media_port>7078</remote_media_port>
<rtp_audio_recv_pt>18</rtp_audio_recv_pt>
<dtmf_type>info</dtmf_type>
<remote_video_media_flow>sendrecv</remote_video_media_flow>
<video_possible>true</video_possible>
<remote_video_ip>172.16.100.124</remote_video_ip>
<remote_video_port>9078</remote_video_port>
<rtp_video_fmtp>profile-level-id%3D42801F</rtp_video_fmtp>
<rtp_video_pt>102</rtp_video_pt>
<rtp_video_recv_pt>102</rtp_video_recv_pt>
<rtp_remote_video_rtcp_port>9079</rtp_remote_video_rtcp_port>
<bridge_channel>sofia/internal-video/990003%40192.168.2.22</bridge_channel>
<bridge_uuid>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</bridge_uuid>
<signal_bond>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</signal_bond>
<original_destination_number>990005</original_destination_number>
<original_caller_id_name>990003</original_caller_id_name>
<original_caller_id_number>990003</original_caller_id_number>
<transfer_history>1742800739%3A56fb6621-8f08-4cff-b350-c1dc53731a4f%3Auuid_br%3A5a4c45ba-6c22-4e21-bce8-fde0e06139f3</transfer_history>
<transfer_source>1742800739%3A56fb6621-8f08-4cff-b350-c1dc53731a4f%3Auuid_br%3A5a4c45ba-6c22-4e21-bce8-fde0e06139f3</transfer_source>
<switch_m_sdp>v%3D0%0D%0Ao%3D990003%202049%20942%20IN%20IP4%20192.168.2.24%0D%0As%3DTalk%0D%0Ac%3DIN%20IP4%20192.168.2.24%0D%0At%3D0%200%0D%0Am%3Daudio%2056067%20RTP/AVP%2018%0D%0Aa%3Dfmtp%3A18%20annexb%3Dyes%0D%0Aa%3Dsendrecv%0D%0Am%3Dvideo%2056069%20RTP/AVP%2096%0D%0Aa%3Drtpmap%3A96%20H264/90000%0D%0Aa%3Dfmtp%3A96%20profile-level-id%3D42801F%0D%0Aa%3Dsendrecv%0D%0Aa%3Drtcp-fb%3A*%20trr-int%201000%0D%0Aa%3Drtcp-fb%3A*%20nack%0D%0Aa%3Drtcp-fb%3A*%20ccm%20tmmbr%0D%0Aa%3Drtcp-fb%3A96%20nack%20pli%0D%0Aa%3Drtcp-fb%3A96%20ccm%20fir%0D%0A</switch_m_sdp>
<call_uuid>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</call_uuid>
<bridge_to>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</bridge_to>
<last_bridge_to>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</last_bridge_to>
</variables>
<callflow dialplan="XML" unique-id="56fb6621-8f08-4cff-b350-c1dc53731a4f" clone-of="9f842aa3-92f3-4319-a55f-2c52b236b21f" profile_index="2">
<caller_profile>
<username>990003</username>
<dialplan>XML</dialplan>
<caller_id_name>990003</caller_id_name>
<caller_id_number>990003</caller_id_number>
<callee_id_name>Outbound Call</callee_id_name>
<callee_id_number>990005</callee_id_number>
<ani>990003</ani>
<aniii></aniii>
<network_addr>192.168.4.18</network_addr>
<rdnis>990005</rdnis>
<destination_number>990005</destination_number>
<uuid>8dc21c06-a91c-467a-88c5-fd0a5dafa406</uuid>
<source>mod_sofia</source>
<transfer_source>1742800739:56fb6621-8f08-4cff-b350-c1dc53731a4f:uuid_br:5a4c45ba-6c22-4e21-bce8-fde0e06139f3</transfer_source>
<context>default</context>
<chan_name>sofia/internal-video/990005@192.168.4.18:55867</chan_name>
<originator>
<originator_caller_profile>
<username>990003</username>
<dialplan>XML</dialplan>
<caller_id_name>990003</caller_id_name>
<caller_id_number>990003</caller_id_number>
<callee_id_name>Outbound Call</callee_id_name>
<callee_id_number>990005</callee_id_number>
<ani>990003</ani>
<aniii></aniii>
<network_addr>192.168.2.24</network_addr>
<rdnis>990005</rdnis>
<destination_number>990005</destination_number>
<uuid>5a4c45ba-6c22-4e21-bce8-fde0e06139f3</uuid>
<source>mod_sofia</source>
<context>default</context>
<chan_name>sofia/internal-video/990003@192.168.2.22</chan_name>
</originator_caller_profile>
</originator>
</caller_profile>
<times>
<created_time>1742800739483601</created_time>
<profile_created_time>1742800739571897</profile_created_time>
<progress_time>1742800712911708</progress_time>
<progress_media_time>0</progress_media_time>
<answered_time>1742800716231627</answered_time>
<bridged_time>1742800739611835</bridged_time>
<last_hold_time>0</last_hold_time>
<hold_accum_time>0</hold_accum_time>
<hangup_time>0</hangup_time>
<resurrect_time>0</resurrect_time>
<transfer_time>0</transfer_time>
</times>
</callflow>
<callflow dialplan="XML" unique-id="9f842aa3-92f3-4319-a55f-2c52b236b21f" profile_index="1">
<caller_profile>
<username>990003</username>
<dialplan>XML</dialplan>
<caller_id_name>990003</caller_id_name>
<caller_id_number>990003</caller_id_number>
<callee_id_name>Outbound Call</callee_id_name>
<callee_id_number>990005</callee_id_number>
<ani>990003</ani>
<aniii></aniii>
<network_addr>192.168.4.18</network_addr>
<rdnis>990005</rdnis>
<destination_number>990005</destination_number>
<uuid>8dc21c06-a91c-467a-88c5-fd0a5dafa406</uuid>
<source>mod_sofia</source>
<context>default</context>
<chan_name>sofia/internal-video/990005@192.168.4.18:55867</chan_name>
<originator>
<originator_caller_profile>
<username>990003</username>
<dialplan>XML</dialplan>
<caller_id_name>990003</caller_id_name>
<caller_id_number>990003</caller_id_number>
<callee_id_name></callee_id_name>
<callee_id_number></callee_id_number>
<ani>990003</ani>
<aniii></aniii>
<network_addr>192.168.2.24</network_addr>
<rdnis>990005</rdnis>
<destination_number>990005</destination_number>
<uuid></uuid>
<source>mod_sofia</source>
<context>default</context>
<chan_name></chan_name>
</originator_caller_profile>
</originator>
</caller_profile>
<times>
<created_time>1742800739483601</created_time>
<profile_created_time>1742800712531680</profile_created_time>
<progress_time>1742800712911708</progress_time>
<progress_media_time>0</progress_media_time>
<answered_time>1742800716231627</answered_time>
<bridged_time>0</bridged_time>
<last_hold_time>0</last_hold_time>
<hold_accum_time>0</hold_accum_time>
<hangup_time>0</hangup_time>
<resurrect_time>1742800739483595</resurrect_time>
<transfer_time>1742800739571897</transfer_time>
</times>
</callflow>
</cdr>
多节点配置
主从模式
配置主机与从机的switchname相同,当切换到从机时,确保从机ip与主机相同
autoload_configs/switch.conf.xml
<param name="switchname" value="freeswitch01"/>
多节点模式(分布式)
实测不同节点配置不同的switchname,另一个节点也会尝试恢复会话,当尝试恢复失败(bind ip 端口失败)时会将记录删除,可能会导致异常节点恢复时无法正常恢复会话。
暂不明确是设计还是缺陷。
暂不推荐在此模式下使用。
会话恢复
手动恢复
fs_cli -x 'sofia recover'
or
fs_cli -x 'fsctl recover'
fs启动时自动恢复
<X-PRE-PROCESS cmd="set" data="api_on_startup=fsctl recover"/>
or
<X-PRE-PROCESS cmd="set" data="api_on_startup=sofia recover"/>
结果验证
总共测试三项,echo,bridge,conference均能正常恢复会话,语音恢复较快,视频恢复较慢(与编解码相关,实际rtp恢复速度与语言相近)。
浙公网安备 33010602011771号