terminate called after throwing an instance of ‘std::regex_error‘

被自己蠢笑了。

事情缘由:今天整理项目的时候,发现了此前能跑通的服务器,今天重新跑的时候,突然跑不通了。

svr.listen("0.0.0.0", 8081);

当浏览器访问localhost:8081时,访问失败,此时看到终端输出了这段信息:

terminate called after throwing an instance of 'std::regex_error'   what():  regex_error Aborted (core dumped)

 很明显的就是,只要访问localhost:8081时,连接就会被重置。

[root@localhost asuiiiyi]# netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
udp        0      0 192.168.122.1:53        0.0.0.0:*                          
udp        0      0 0.0.0.0:67              0.0.0.0:*                          
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 0.0.0.0:111             0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp        0      0 0.0.0.0:53687           0.0.0.0:*                          
udp        0      0 0.0.0.0:900             0.0.0.0:*                          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                          
udp6       0      0 :::111                  :::*                               
udp6       0      0 ::1:323                 :::*                               
udp6       0      0 :::900                  :::*                               
[root@localhost asuiiiyi]# curl "http://127.0.0.1:8081/s?word=split"
curl: (56) Recv failure: Connection reset by peer
[root@localhost asuiiiyi]# netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::111                  :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
udp        0      0 192.168.122.1:53        0.0.0.0:*                          
udp        0      0 0.0.0.0:67              0.0.0.0:*                          
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
udp        0      0 0.0.0.0:111             0.0.0.0:*                          
udp        0      0 127.0.0.1:323           0.0.0.0:*                          
udp        0      0 0.0.0.0:53687           0.0.0.0:*                          
udp        0      0 0.0.0.0:900             0.0.0.0:*                          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                          
udp6       0      0 :::111                  :::*                               
udp6       0      0 ::1:323                 :::*                               
udp6       0      0 :::900                  :::*   

上一秒还在监听端口8081,执行完curl之后,马上断连。

排查情况:

  • 分离后端进行debug:通过
  • 文件路径核对:通过

所以我怀疑是编译器某些硬编码上出现了问题时,我使用root用户重新用g++进行编译文件,然后跑通了...

后面发现

本地用户的G++版本是centos 7 默认的4.8.5,而root用户,在此前更新G++版本至8.3.1

总结:

G++版本较低可能会影响正则表达式的编译和运行,特别是对于一些较新的正则表达式特性和优化。

  1. 正则表达式语法支持:较低版本的编译器可能不支持某些较新的正则表达式语法,导致编译错误或运行时行为不一致。

  2. 性能和优化:较新版本的编译器通常会对正则表达式的性能进行优化,包括编译和匹配速度。较低版本可能缺少这些优化,导致程序运行速度较慢或性能下降。

  3. 兼容性问题:一些标准库或第三方库可能依赖于较新版本编译器提供的正则表达式功能。使用较低版本的编译器可能会导致这些库无法编译或运行。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值