HarmonyOS鸿蒙Next中使用web和XComponent组件,当断开网络链接后,页面崩溃,求指导

HarmonyOS鸿蒙Next中使用web和XComponent组件,当断开网络链接后,页面崩溃,求指导

class webMsg {
  constructor() {
  }

  viewMessage(type: String, data: String) {
    console.log(`viewMessage: type:${type}, data:${data}`)
  }
}

@HMRouter({ pageUrl: 'LiveRoomPage' })
@ComponentV2
export struct LiveRoomPage {
  @Local webMsgObj: webMsg = new webMsg();
  @Local uid: number = 0;
  @Local remoteUid: number = 0;
  @Local localUid: number = 0;
  @Local appId: string = '';
  @Local liveId: string = '';
  @Local roomId: string = '';
  @Local tokenId: string = '';
  @Local rtcEngine: RtcEngine | undefined = undefined;

  context: Context | undefined = this.getUIContext().getHostContext()
  controller: webview.WebviewController = new webview.WebviewController();

  windowClass = (this.context as common.UIAbilityContext).windowStage.getMainWindowSync();
  private async lockLandscape() {
    try {
      if (this.windowClass) {
        // 锁定为横屏(支持左右横屏自动旋转)
        await this.windowClass.setPreferredOrientation(window.Orientation.LANDSCAPE);
      }
    } catch (err) {
      console.error('Failed to set orientation:', JSON.stringify(err));
    }
  }

  private async unlockOrientation() {
    try {
      if (this.windowClass) {
        // 恢复为 UNSPECIFIED(允许系统自动选择,通常回到竖屏)
        await this.windowClass.setPreferredOrientation(window.Orientation.UNSPECIFIED);
      }
    } catch (err) {
      console.error('Failed to reset orientation:', JSON.stringify(err));
    }
  }

  async aboutToAppear(): Promise<void> {
    try {
      // 进入页面时,强制横屏
      this.lockLandscape();
      webview.WebviewController.setWebDebuggingAccess(true);
      this.liveId = HMRouterMgr.getCurrentParam(HMParamType.routeParam) as string;

      const tokenAndAppId = await getToken(this.liveId);
      this.appId = tokenAndAppId.appId;
      this.roomId = tokenAndAppId.roomId;
      this.tokenId = tokenAndAppId.token;
      this.uid = tokenAndAppId.userId;

      this.joinChannel();
    } catch (error) {
      console.error(`ErrorCode: ${(error as BusinessError).code},  Message: ${(error as BusinessError).message}`);
    }
  }
  async joinChannel(): Promise<void> {
    console.log('LiveRoomPage joinChannel')
    this.rtcEngine = agoraRTC.initRtcEngine(this.context);

    let option: ChannelMediaOptions = new ChannelMediaOptions();
    // 自动订阅所有音频流
    option.autoSubscribeAudio = true;
    // 自动订阅所有视频流
    option.autoSubscribeVideo = true;
    // 发布摄像头采集的视频
    option.publishCameraTrack = true;
    // 发布麦克风采集的音频
    option.publishMicrophoneTrack = true;
    // 设置频道场景为直播
    option.channelProfile = Constants.ChannelProfile.LIVE_BROADCASTING;
    // 设置用户角色为主播;如果要将用户角色设置为观众,保持默认值即可
    option.clientRoleType = Constants.ClientRole.AUDIENCE;
    // 使用临时 Token 加入频道,在这里传入你的项目的 Token 和频道名
    // uid 为 0,表示由服务器分配 uid,分配的 uid 将通过 onJoinChannelSuccess 回调返回
    let ret = this.rtcEngine?.joinChannelWithOptions(this.tokenId, this.roomId, this.uid, option)
    if (ret != Constants.ErrorCode.ERR_OK) {
      console.log("joinChannelWithOptions error " + ret + " : " + RtcEngine.getErrorDescription(ret))
      return
    }
  }

  aboutToDisappear(): void {
    // 离开页面时,恢复自动旋转(或竖屏)
    this.unlockOrientation();
    if (this.rtcEngine != undefined) {
      this.rtcEngine?.leaveChannel()
      agoraRTC.destroyRtcEngine();
    }

    this.rtcEngine = undefined;

  }

  build() {
    Row() {
      Web({ src: 'website', controller: this.controller })
        .javaScriptAccess(true)
        .domStorageAccess(true)
        .javaScriptProxy({
          object: this.webMsgObj,
          name: 'webMsg',
          methodList: ['viewMessage'],
          controller: this.controller
        }).backgroundColor(Color.Black).layoutWeight(6)
        .expandSafeArea([SafeAreaType.SYSTEM])
      Column() {
        // 视频区域
        XComponent({
          id: 'preview_remote',
          type: XComponentType.SURFACE,
          libraryname: Constants.AGORA_LIB_NAME
        }).height('50%').aspectRatio(1.78).layoutWeight(3)
          .backgroundColor(Color.Gray)
        Tabs() {
          TabContent() {
          }.tabBar('1')

          TabContent() {
          }.tabBar('2')
        }
        .backgroundColor(Color.Pink).layoutWeight(7)
        .vertical(true)
      }
      .justifyContent(FlexAlign.Center)
      .layoutWeight(4)
      .backgroundColor(Color.Black)
    }.width('100%')
    .height('100%')
  }
}
evice info:HUAWEI Pura 70 Pro
Build info:HBN-AL00 6.0.0.125(SP8C00E125R5P7)
Fingerprint:6a2c10bba9de714c4d769edae5b4ea1a19985dd7881bf1df4b4b2307f8d6129a
Module name:com.example.myapplication
Version:1.0.0
VersionCode:1000000
PreInstalled:No
Foreground:Yes
Page switch history:
  23:08:40.750 :enters foreground
  23:08:26.846 /ets/pages/Index:LiveRoomPage
  23:08:21.302 /ets/pages/Index:LiveListPage
  23:08:20.323 :enters foreground
  23:08:16.607 :enters foreground
  23:08:11.100 /ets/pages/Index:LiveRoomPage
  23:08:10.418 /ets/pages/Index:LiveListPage
  23:08:09.714 /ets/pages/Index:MainPage
  23:08:05.207 :enters foreground
Timestamp:2026-01-17 23:08:42.512
Pid:20786
Uid:20020190
Process name:com.example.myapplication
Process life time:40s
Process Memory(kB): 384471(Rss)
Device Memory(kB): Total 11862976, Free 657916, Available 3166208
Reason:Signal:SIGBUS(BUS_ADRALN)@0x0000000000000001 
Fault thread info:
Tid:21000, Name:NetworkService
#00 pc 0000000000000001 Not mapped
#01 pc 00000000001dfed4 /system/lib/ld-musl-aarch64.so.1(signal_chain_handler+920)(f83970fe414a8a0eaeb706794b1b2f7b)
#02 pc 0000000000001cc4 [shmm]
#03 pc 0000000000001468 [shmm]
#04 pc 0000000000160428 /system/lib/ld-musl-aarch64.so.1(__write_chk+76)(f83970fe414a8a0eaeb706794b1b2f7b)
#05 pc 0000000004e64964 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SocketPosix::Write(net::PAC_IOBuffer*, int, base::PAC_OnceCallback<void (int)>, net::PAC_NetworkTrafficAnnotationTag const&)+112)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#06 pc 0000000004e662b8 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_TCPSocketPosix::Write(net::PAC_IOBuffer*, int, base::PAC_OnceCallback<void (int)>, net::PAC_NetworkTrafficAnnotationTag const&)+200)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#07 pc 0000000004dda030 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_TCPClientSocket::Write(net::PAC_IOBuffer*, int, base::PAC_OnceCallback<void (int)>, net::PAC_NetworkTrafficAnnotationTag const&)+168)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#08 pc 0000000004dc792c /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SocketBIOAdapter::SocketWrite()+176)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#09 pc 0000000004dc7dd4 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SocketBIOAdapter::BIOWriteWrapper(PAC_bio_st*, char const*, int)+568)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#10 pc 00000000049a317c /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(bssl::ssl_write_buffer_flush(PAC_ssl_st*)+428)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#11 pc 000000000499fa68 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(bssl::do_tls_write(PAC_ssl_st*, unsigned long*, unsigned char, bssl::PAC_Span<unsigned char const>)+668)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#12 pc 000000000499f74c /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(bssl::tls_write_app_data(PAC_ssl_st*, bool*, unsigned long*, bssl::PAC_Span<unsigned char const>)+292)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#13 pc 00000000049acf64 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(SSL_write+260)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#14 pc 0000000004dd36a4 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SSLClientSocketImpl::DoPayloadWrite()+80)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#15 pc 0000000004dd3570 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SSLClientSocketImpl::Write(net::PAC_IOBuffer*, int, base::PAC_OnceCallback<void (int)>, net::PAC_NetworkTrafficAnnotationTag const&)+132)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#16 pc 0000000004dffa24 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(net::PAC_SpdySession::PumpWriteLoop(net::PAC_SpdySession::WriteState, int)+824)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#17 pc 000000000478e6bc /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::PAC_TaskAnnotator::RunTaskImpl(base::PAC_PendingTask&)+260)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#18 pc 00000000047b0ad4 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::sequence_manager::internal::PAC_ThreadControllerWithMessagePumpImpl::DoWork()+2040)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#19 pc 000000000481f690 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::PAC_MessagePumpEpoll::Run(base::PAC_MessagePump::PAC_Delegate*)+500)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#20 pc 00000000047b1268 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::sequence_manager::internal::PAC_ThreadControllerWithMessagePumpImpl::Run(bool, base::PAC_TimeDelta)+324)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#21 pc 00000000047703ec /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::PAC_RunLoop::Run(base::PAC_Location const&)+188)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#22 pc 00000000047d2fd8 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::PAC_Thread::Run(base::PAC_RunLoop*)+60)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#23 pc 00000000047d3274 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::PAC_Thread::ThreadMain()+644)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#24 pc 00000000047e61b0 /data/storage/el1/bundle/arkwebcore/libs/arm64/libarkweb_engine.so(base::(anonymous namespace)::ThreadFunc(void*)+376)(f7e01656d015e2dc2bc94779efeeea1beb712f1b)
#25 pc 00000000001d0858 /system/lib/ld-musl-aarch64.so.1(start+240)(f83970fe414a8a0eaeb706794b1b2f7b)
Registers:
x0:000000000000000d x1:0000005bbe9a0c00 x2:0000005bbe9a0c80 x3:0000000000000000
x4:0000000000000011 x5:000000000000038e x6:0000005bbe9a01e1 x7:0000005b3b1ac824
x8:0000000000000001 x9:0000000000000051 x10:000000000000000e x11:0000000035a50276
x12:000000003b9ac9ff x13:aaaaaaaa245ca075 x14:000000003b9ac9ff x15:0000005b3b1abc02
x16:0000005bbe9a0620 x17:0000005bbe9a0940 x18:000000000000000e x19:000000000000000d
x20:0000005b3b664870 x21:0000005bbe9a0c80 x22:0000005b3b66c000 x23:0000000000000004
x24:0000005bbe9a0c00 x25:0000000000005203 x26:0000000000000000 x27:0000000000000000
x28:0000005b3b664a28 x29:0000005bbe9a0b70
lr:0000005b3b35eed8 sp:0000005bbe9a09c0 pc:0000000000000001
pstate:0000000000001800 esr:000000008a000000

正常打开页面,观看agora直播,步骤(1.下拉状态栏关闭WiFi、数据,上拉状态栏回到页面;2.置于后台几十秒回到页面)出现闪退。系统6.0.0.120正常,升到125后步骤1必现


更多关于HarmonyOS鸿蒙Next中使用web和XComponent组件,当断开网络链接后,页面崩溃,求指导的实战教程也可以访问 https://www.itying.com/category-93-b0.html

9 回复

开发者您好,需要您提供下面的信息方便进一步分析问题:

1.日志信息,上面您提供了崩溃的cppcrash信息,麻烦请您在提供下hilog日志信息;

2.跟您确认下您编译项目的api版本信息;

3.您agora直播这里功能的实现,使用是否是三方库的能力,麻烦提供下三方库的链接,或者确认下是否使用的是这个三方库:[@shengwang/rtc-full](https://ohpm.openharmony.cn/#/cn/detail/@shengwang%2Frtc-full);

4.是否方便提供一个测试的hap包,方便我们这边复现一下您的这个问题

更多关于HarmonyOS鸿蒙Next中使用web和XComponent组件,当断开网络链接后,页面崩溃,求指导的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


三方库:@shengwang/rtc-full;编译项目的api版本信息:13、20都会崩溃

HiLog: 01-22 11:00:11.496 56987 57261 I A04510/com.example.myapplication/chromium: [res_parallel_preload_ctrler.h:21] PRPPreload.ResParallelPreloadCtrler::~ResParallelPreloadCtrler 01-22 11:00:11.497 56987 57261 I A04510/com.example.myapplication/chromium: [disk_cache_file.h:88] PRPPreload.DiskCacheFile::~DiskCacheFile 01-22 11:00:12.207 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_delegate.cc:3169] NWebDelegate::OnFocus set web focus, nweb_id = 1 01-22 11:00:12.207 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_handler_delegate.cc:3231] nweb_handler request focus successful, source = 1, nweb_id = 1 01-22 11:00:12.207 56987 56987 I A04510/com.example.myapplication/cef: [render_widget_host_view_osr.cc:1668] CefRenderWidgetHostViewOSR::SetFocus:1 01-22 11:00:12.207 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_inputmethod_handler.cc:478] ReAttchOnfocus, don’t need reattach input method 01-22 11:00:12.214 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_inputmethod_handler.cc:1149] NWebInputMethodHandler is_editable_node_ = 0 01-22 11:00:12.214 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_impl.cc:4972] no hittest edit text, web close keyboard. 01-22 11:00:12.575 56987 57249 W C03F00/MUSL-SIGCHAIN: signal_chain_handler call 2 rd sigchain action for signal: 13 sca_sigaction=5b3c986564 noreturn=0 FREEZE_signo_13 thread_list_lock_status:-1 tl_lock_count=0 tl_lock_waiters=0 tl_lock_tid_fail=-1 tl_lock_count_tid=599 tl_lock_count_fail=-10000 tl_lock_count_tid_sub=599 thread_list_lock_after_lock=57225 thread_list_lock_pre_unlock=57243 thread_list_lock_pthread_exit=57225 thread_list_lock_tid_overlimit=-1 tl_lock_unlock_count=0 __pthread_gettid_np_tl_lock=0 __pthread_exit_tl_lock=0 __pthread_create_tl_lock=0 __pthread_key_delete_tl_lock=0 _synccall_tl_lock=0 membarrier_tl_lock=0 install_new_tls_tl_lock=0 set_syscall_hooks_tl_lock=0 set_syscall_hooks_linux_tl_lock=0 fork_tl_lock=0 register_count=0 custom_hook_flag=0g_dlcloseLockStatus=0g_dlcloseLockLastExitTid=57243 01-22 11:00:12.576 56987 57249 I C02D11/DfxSignalHandler: DFX_SigchainHandler :: signo(13), si_code(0), pid(56987), tid(57249). 01-22 11:00:12.576 56987 57249 I C02D11/DfxSignalHandler: g_GetStackIdFunc <private>. 01-22 11:00:12.576 56987 57249 I C02D11/DfxSignalHandler: DFX_SigchainHandler :: signo(13), pid(56987), processName(com.example.myapplication), threadName(NetworkService). 01-22 11:00:12.580 56987 57085 I A04510/com.example.myapplication/chromium: [net_connect_adapter_impl.cpp:313] NetConnCallback enter, NetLost, net id = 189. 01-22 11:00:12.580 56987 57085 I A04510/com.example.myapplication/chromium: [network_change_notifier_passive_for_include.cc:125] ohos_network NetUnavailable 01-22 11:00:12.580 56987 57085 I A04510/com.example.myapplication/chromium: [network_change_notifier_passive_for_include.cc:213] ohos_network ConnectionTypeChangedTo, net_id 189, net_id -1, type 2, type 6, network_for_dns -1 01-22 11:00:12.580 56987 57085 E A04510/com.example.myapplication/chromium: [network_change_notifier_passive_for_include.cc:311] OnConnectionChanged, ohos_network dns server is empty. 01-22 11:00:12.581 56987 57085 I A04510/com.example.myapplication/chromium: [network_change_notifier_passive_for_include.cc:243] ohos_network ConnectionTypeChangedTo, net_id -1, subtype 0, subtype 1 01-22 11:00:12.609 56987 57226 I A04510/com.example.myapplication/chromium: [net_connect_adapter_impl.cpp:70] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 5 01-22 11:00:12.611 56987 57997 I A04510/com.example.myapplication/chromium: [net_connect_adapter_impl.cpp:70] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 1 01-22 11:00:12.613 56987 57996 I A04510/com.example.myapplication/chromium: [net_event_adapter_impl.cpp:72] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 5 01-22 11:00:12.613 56987 57996 I A04510/com.example.myapplication/chromium: [captive_portal_tab_helper_ohos.cc:43] OnConnectivityChanged for captive_portal bearType:1 connState:5 01-22 11:00:12.613 56987 57996 I A04510/com.example.myapplication/chromium: [net_event_adapter_impl.cpp:72] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 1 01-22 11:00:12.615 56987 57085 I A04510/com.example.myapplication/chromium: [net_connect_adapter_impl.cpp:313] NetConnCallback enter, NetLost, net id = 189. 01-22 11:00:12.615 56987 57085 I A04510/com.example.myapplication/chromium: [network_change_notifier_passive_for_include.cc:125] ohos_network NetUnavailable 01-22 11:00:12.722 56987 57249 E C02D11/DfxSignalHandler: dummy exit (0) 01-22 11:00:12.806 56987 57057 I C03F00/com.example.myapplication/ArkCompiler: [gc] SmartGC: app cold start finished 01-22 11:00:12.827 56987 57226 I A04510/com.example.myapplication/chromium: [net_connect_adapter_impl.cpp:70] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 1 01-22 11:00:12.828 56987 57999 I A04510/com.example.myapplication/chromium: [net_event_adapter_impl.cpp:72] receive COMMON_EVENT_CONNECTIVITY_CHANGE type: 1 code: 1 01-22 11:00:14.006 56987 56987 I C04202/com.example.myapplication/WMSMain: NotifyMemoryLevel: level: 0 01-22 11:00:14.006 56987 56987 I C04200/com.example.myapplication/WMS: NotifyMemoryLevel: id: 893, level: 0 01-22 11:00:14.006 56987 56987 I C03900/com.example.myapplication/Ace: [(-2:100000:singleton)] [com.example.myapplication][entry][100000]: NotifyMemoryLevel: 0 01-22 11:00:14.007 56987 56987 I C01332/com.example.myapplication/UIAbility: [JUA1854]JsUIAbility call js, name: onMemoryLevel 01-22 11:00:14.007 56987 56987 I C01332/com.example.myapplication/UIAbility: [JUA1899]end, name: onMemoryLevel, time: 0 01-22 11:00:14.007 56987 56987 W C01317/com.example.myapplication/AppKit: [js_ability_stage567]Not found stage 01-22 11:00:14.008 56987 56987 E C01305/com.example.myapplication/Base: [zip_file.cpp(Open:280)]realpath error: 2, pathName: /module_update/ArkWebCore/app/com.huawei.hmos.arkwebcore/ArkWebCore.hap 01-22 11:00:14.008 56987 56987 E C04500/com.example.myapplication/webadapter: GetArkWebVersion: Failed to initialize extractor for HAP file: /module_update/ArkWebCore/app/com.huawei.hmos.arkwebcore/ArkWebCore.hap 01-22 11:00:14.008 56987 56987 E C01305/com.example.myapplication/Base: [zip_file.cpp(Open:280)]realpath error: 2, pathName: /system/app/com.ohos.arkwebcore/ArkWebCore.hap 01-22 11:00:14.008 56987 56987 E C04500/com.example.myapplication/webadapter: GetArkWebVersion: Failed to initialize extractor for HAP file: /system/app/com.ohos.arkwebcore/ArkWebCore.hap 01-22 11:00:14.008 56987 56987 E C04500/com.example.myapplication/webadapter: GetArkWebVersion: Failed to get ArkWeb version from any of the specified paths 01-22 11:00:14.009 56987 56987 I A04510/com.example.myapplication/chromium: [nweb_impl.cc:3406] NWebImpl::NotifyMemoryLevel MEMORY_PRESSURE_LEVEL_MODERATE 01-22 11:00:14.161 56987 57249 E C02D11/DfxSignalHandler: dummy exit (0) 01-22 11:00:14.161 56987 57249 I C02D11/DfxSignalHandler: crash processdump unwind finish, unwind success Flag 0, blockFlag 0 01-22 11:00:14.161 56987 57249 I C02D11/DfxSignalHandler: Finish handle signal(13) in 56987:57249. 01-22 11:00:14.161 56987 57249 W C03F00/MUSL-SIGCHAIN: signal_chain_handler call usr sigaction for signal: 13 sig_action.sa_sigaction=1 01-22 11:00:14.161 56987 57249 W C03F00/MUSL-SIGCHAIN: signal_chain_handler call 2 rd sigchain action for signal: 7 sca_sigaction=5b3c986564 noreturn=0 FREEZE_signo_7 thread_list_lock_status:-1 tl_lock_count=0 tl_lock_waiters=0 tl_lock_tid_fail=-1 tl_lock_count_tid=599 tl_lock_count_fail=-10000 tl_lock_count_tid_sub=599 thread_list_lock_after_lock=57093 thread_list_lock_pre_unlock=57996 thread_list_lock_pthread_exit=57093 thread_list_lock_tid_overlimit=-1 tl_lock_unlock_count=0 __pthread_gettid_np_tl_lock=0 __pthread_exit_tl_lock=0 __pthread_create_tl_lock=0 __pthread_key_delete_tl_lock=0 __synccall_tl_lock=0 __membarrier_tl_lock=0 install_new_tls_tl_lock=0 set_syscall_hooks_tl_lock=0 set_syscall_hooks_linux_tl_lock=0 fork_tl_lock=0 register_count=0 __custom_hook_flag=0g_dlcloseLockStatus=0g_dlcloseLockLastExitTid=57243 01-22 11:00:14.161 56987 57249 I C02D11/DfxSignalHandler: DFX_SigchainHandler :: signo(7), si_code(1), pid(56987), tid(57249). 01-22 11:00:14.161 56987 57249 I C02D11/DfxSignalHandler: g_GetStackIdFunc <private>. 01-22 11:00:14.161 56987 57249 I C02D11/DfxSignalHandler: DFX_SigchainHandler :: signo(7), pid(56987), processName(com.example.myapplication), threadName(NetworkService). 01-22 11:00:14.172 0 0 I C00000/HiLog: crash time: 1769050814161 call time: 1769050814162117016 accept time: 1769050814165522224,

开发者您好,麻烦再提供下完整的cppcrash日志文件,可以在hilog旁边的faultlog导出完整的崩溃日志。

使用Docker安装和运行MySQL

1. 拉取MySQL镜像

docker pull mysql:8.0

2. 运行MySQL容器

docker run -d \
  --name mysql8 \
  -p 3306:3306 \
  -e MYSQL_ROOT_PASSWORD=123456 \
  mysql:8.0

3. 进入MySQL容器

docker exec -it mysql8 bash

4. 登录MySQL

mysql -u root -p

输入密码:123456

5. 修改root用户允许远程连接

-- 使用mysql数据库
use mysql;

-- 查看用户表
select host, user from user;

-- 修改root用户的host为%,允许所有IP连接
update user set host='%' where user='root';

-- 刷新权限
flush privileges;

6. 退出MySQL和容器

-- 退出MySQL
exit;

-- 退出容器
exit;

7. 使用Navicat连接MySQL

  1. 打开Navicat,点击"连接" -> “MySQL”
  2. 填写连接信息:
    • 连接名:自定义
    • 主机:localhost 或 服务器IP
    • 端口:3306
    • 用户名:root
    • 密码:123456
  3. 点击"测试连接",显示连接成功即可

注意事项

  1. 生产环境请使用更复杂的密码
  2. 根据实际情况调整端口映射
  3. 建议配置数据卷持久化数据
  4. 可根据需要调整MySQL配置参数

demo ets源码,需要安装agora sdk和 @hadss/hmrouter,plugin

有权限上传了完整的在附件里

在鸿蒙Next中,Web组件与XComponent组件断开网络后崩溃,通常与Web组件的网络资源加载失败有关。XComponent组件本身不依赖网络,但若其渲染内容由Web组件提供,则Web组件的崩溃可能导致整体页面异常。建议检查Web组件的onError回调,处理网络中断时的资源加载失败情况,避免页面崩溃。

根据你提供的崩溃日志,问题出在 NetworkService 线程尝试向一个无效的内存地址(0x0000000000000001)写入数据,触发了 SIGBUS (BUS_ADRALN) 信号导致崩溃。调用栈显示崩溃发生在网络库(libarkweb_engine.so)进行SSL/TLS数据写入的过程中。

结合你的描述——在HarmonyOS 6.0.0.125版本上,断开网络连接(关闭WiFi/数据)后返回页面必现崩溃,而在6.0.0.120版本正常——这很可能是一个系统升级引入的Web引擎(ArkWeb)在网络状态异常处理时的兼容性问题或缺陷。

问题根因分析:

  1. 直接原因:当网络连接突然断开时,页面中的 Web 组件(可能加载了含有活跃网络请求的网页)或与之关联的 XComponent(集成了声网Agora RTC SDK)仍在尝试进行网络通信(例如,尝试重连、发送心跳或数据)。
  2. 系统差异:在系统版本125中,底层网络栈或ArkWeb引擎对“socket在断开后立即进行写操作”这一场景的处理逻辑可能发生了变化,未能正确校验socket状态或清理资源,导致访问了非法内存地址。
  3. 线程冲突:崩溃发生在 NetworkService 线程,这是一个系统管理的网络相关线程。你的应用代码(Web 组件、Agora RTC)的网络活动可能在该线程中执行,当应用层与系统层对网络断开的响应不同步时,引发了内存访问错误。

排查与解决方向:

1. 应用层强化网络状态监听与保护:

  • aboutToAppear 或页面显示时,使用 @ohos.net.connection 模块监听网络连接状态变化(NET_AVAILABLENET_CAPABILITIES_CHANGENET_LOST)。
  • 当检测到网络断开(NET_LOST)时,立即暂停或销毁 Web 组件的加载活动(例如,通过 controller 停止加载),并调用 Agora RTC SDK 的 leaveChannel 方法离开频道,停止所有网络传输。可以参考 aboutToDisappear 中的清理逻辑。
  • 在网络恢复后,再重新初始化 Web 组件和 Agora RTC 连接。

2. 优化组件生命周期管理:

  • 确保 aboutToDisappear 中的资源释放(leaveChannel, destroyRtcEngine)是可靠且及时的。考虑在页面失去焦点(例如进入后台)时也触发类似的清理操作,而不仅仅是在页面销毁时。
  • 检查 Web 组件加载的网页内容。如果网页内部有持续的网络活动(如WebSocket、轮询),尝试在网页脚本中增加对 visibilitychangepagehide 事件的监听,在页面不可见时主动停止网络活动。

3. 规避与降级:

  • 由于此问题在系统版本120上未出现,在125上必现,属于系统级兼容性问题。在系统修复前,一个直接的规避方法是引导用户避免在观看直播时主动断开网络并快速返回应用。
  • 如果条件允许,可以尝试将 Web 组件替换为更简单的原生组件来展示部分内容,减少对复杂网页的依赖,以降低触发该底层缺陷的概率。

总结: 当前最可行的方案是在应用层增加健壮的网络状态监听,在网络断开时主动暂停 WebXComponent(Agora RTC)的所有网络活动,待网络恢复后再重新连接。这需要修改 LiveRoomPage 的代码,增加对 @ohos.net.connection 模块的使用。同时,关注HarmonyOS后续的系统更新,该问题可能会在未来的版本中得到修复。

回到顶部