如何解决Network单元测试用例crash问题
========================

**问题描述**

组件依赖已更新到最新。network源码编译时出现如下报错：

Fingerprint:8c83cd8bd1e043ceecdb478f0ca56f241b09616da77300b1a834d50620c6cdd9Module name:msc\_cpp\_testTimestamp:2024-03-22 15:35:05.292Pid:59626Uid:0Process name:/data/local/tmp/msc\_cpp\_test/msc\_cpp\_testReason:Signal:SIGABRT(SI\_TKILL)@0x000000000000e8ea from:59626:0Fault thread Info:Tid:59626, Name:msc\_cpp\_test#00 pc 0000000000185ca8 /system/lib/ld-musl-aarch64.so.1(raise+188)(bad62e733958f8d89d07480a2491abc9)#01 pc 00000000001381a8 /system/lib/ld-musl-aarch64.so.1(abort+20)(bad62e733958f8d89d07480a2491abc9)#02 pc 000000000005bef4 /system/lib64/libclang\_rt.asan.so(d3894082b99f633c446cd1895b6190bd6a0bad31)#03 pc 000000000005a48c /system/lib64/libclang\_rt.asan.so(d3894082b99f633c446cd1895b6190bd6a0bad31)#04 pc 00000000000d64e8 /system/lib64/libclang\_rt.asan.so(d3894082b99f633c446cd1895b6190bd6a0bad31)#05 pc 00000000000d88ac /system/lib64/libclang\_rt.asan.so(d3894082b99f633c446cd1895b6190bd6a0bad31)#06 pc 00000000000d2624 /system/lib64/libclang\_rt.asan.so(\_\_asan\_memmove+468)(d3894082b99f633c446cd1895b6190bd6a0bad31)#07 pc 000000000064a264 /data/local/tmp/msc\_cpp\_test/libnetwork.so(std::\_\_n1::pair<int const\*, int\*> std::\_\_n1::\_\_copy\_impl\[abi:v15004\]<int const, int, void>(int const\*, int const\*, int\*)+376)(f3db319579d1a289ab34f7fab2eb24eb1da4921e)./llvm-addr2line -Cfpie libnetwork.so 000000000064a264mt\_network::WebSocket::Impl::Impl() at /Users/xxx/workspace/workspace/123460300/22012/s/network/src/main/cpp/websocket/websocket.cpp:114#08 pc 0000000000649ab0 /data/local/tmp/msc\_cpp\_test/libnetwork.so(std::\_\_n1::pair<int const\*, int\*> std::\_\_n1::\_\_copy\[abi:v15004\]<int const\*, int const\*, int\*, 0>(int const\*, int const\*, int\*)+600)(f3db319579d1a289ab34f7fab2eb24eb1da4921e)./llvm-addr2line -Cfpie libnetwork.so 0000000000649ab0unsigned long std::\_\_n1::allocator\_traits<std::\_\_n1::allocator<std::\_\_n1::\_\_shared\_ptr\_emplace<mt\_network::WebSocket::Impl, std::\_\_n1::allocator<mt\_network::WebSocket::Impl>>>>::max\_size\[abi:v15004\]<std::\_\_n1::allocator<std::\_\_n1::\_\_shared\_ptr\_emplace<mt\_network::WebSocket::Impl, std::\_\_n1::allocator<mt\_network::WebSocket::Impl>>>, void>(std::\_\_n1::allocator<std::\_\_n1::\_\_shared\_ptr\_emplace<mt\_network::WebSocket::Impl, std::\_\_n1::allocator<mt\_network::WebSocket::Impl>>> const&) at /Users/xxx/.meat/sdk/default/base/native/llvm/bin/…/include/libcxx-ohos/include/c++/v1/\_\_memory/allocator\_traits.h:326#09 pc 0000000000649720 /data/local/tmp/msc\_cpp\_test/libnetwork.so(int\* std::\_\_n1::copy\[abi:v15004\]<int const\*, int\*>(int const\*, int const\*, int\*)+296)(f3db319579d1a289ab34f7fab2eb24eb1da4921e)./llvm-addr2line -Cfpie libnetwork.so 0000000000649720std::\_\_n1::\_\_allocation\_guard<std::\_\_n1::allocator<std::\_\_n1::\_\_shared\_ptr\_emplace<mt\_network::WebSocket::Impl, std::\_\_n1::allocator<mt\_network::WebSocket::Impl>>>>::\_\_release\_ptrabi:v15004 at /Users/xxx/.meat/sdk/default/base/native/llvm/bin/…/include/libcxx-ohos/include/c++/v1/\_\_memory/allocation\_guard.h:6

**解决方案**

网络单元测试用例崩溃的原因是 \`container\_overflow\`。该检测项存在较多误报，目前通过环境变量关闭。测试用例未设置 ASAN 对应的环境变量，因此触发了该检测，导致误报。解决方法是在运行测试用例时设置 ASAN 环境变量。在执行的 Linux 脚本中添加以下两条命令：

sh
export ASAN\_OPTIONS=detect\_container\_overflows=0