IrineSistiana / mosdns

一个 DNS 转发器
GNU General Public License v3.0
3k stars 340 forks source link

[Bug] OP运行mosdns日志出错,似乎不影响使用 #712

Closed lengfwong closed 1 year ago

lengfwong commented 1 year ago

在提交之前,请确认

mosdns 版本

v5.1.3-6

操作系统

OpenWrt

Bug 描述和复现步骤

mosdns启动时,OP日志会出现memory等错误,但似乎不影响使用: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xb52d72]

goroutine 6 [running]: github.com/IrineSistiana/mosdns/v5/pkg/nftset_utils.(NftSetHandler).Close(0xc000010e10?) github.com/IrineSistiana/mosdns/v5/pkg/nftset_utils/handler.go:142 +0x32 github.com/IrineSistiana/mosdns/v5/plugin/executable/nftset.(nftSetPlugin).Close(0xc000010e10) github.com/IrineSistiana/mosdns/v5/plugin/executable/nftset/nftset_linux.go:141 +0x1f github.com/IrineSistiana/mosdns/v5/plugin/executable/sequence.closePlugin(...) github.com/IrineSistiana/mosdns/v5/plugin/executable/sequence/chain.go:219 github.com/IrineSistiana/mosdns/v5/plugin/executable/sequence.(*Sequence).Close(0xc0005d7f68?) github.com/IrineSistiana/mosdns/v5/coremain.NewMosdns.func2.1() github.com/IrineSistiana/mosdns/v5/coremain/mosdns.go:101 +0x1ed created by github.com/IrineSistiana/mosdns/v5/coremain.NewMosdns.func2 in goroutine 36 github.com/IrineSistiana/mosdns/v5/coremain/mosdns.go:94 +0x85

使用的配置文件

log:
  level: info
  file: "/tmp/mosdns.log"

# API 入口设置
api:
  http: "0.0.0.0:9091"

include: []

plugins:
  # 国内域名
  - tag: geosite_cn
    type: domain_set
    args:
      files:
        - "/var/mosdns/geosite_cn.txt"

  # 国内 IP
  - tag: geoip_cn
    type: ip_set
    args:
      files:
        - "/var/mosdns/geoip_cn.txt"

  # 国外域名
  - tag: geosite_no_cn
    type: domain_set
    args:
      files:
        - "/var/mosdns/geosite_geolocation-!cn.txt"

  # 缓存
  - tag: lazy_cache
    type: cache
    args:
      size: 20000
      lazy_cache_ttl: 86400
      dump_file: "/etc/mosdns/cache.dump"
      dump_interval: 600

  # 转发至本地服务器
  - tag: forward_local
    type: forward
    args:
      upstreams:
        - addr: "https://doh.pub/dns-query"
          bootstrap: 180.76.76.76
        - addr: 119.29.29.29

  # 转发至远程服务器
  - tag: forward_remote
    type: forward
    args:
      upstreams:
        - addr: tls://8.8.8.8
          socks5: "127.0.0.1:1081"
          enable_pipeline: false

  # 国内解析
  - tag: local_sequence
    type: sequence
    args:
      - exec: $forward_local

  # 国外解析
  - tag: remote_sequence
    type: sequence
    args:
      - exec: prefer_ipv4
      - exec: $forward_remote
      - exec: nftset inet,fw4,gfwlist,ipv4_addr,32

  # 有响应终止返回
  - tag: has_resp_sequence
    type: sequence
    args:
      - matches: has_resp
        exec: accept

  # fallback 用本地服务器 sequence
  # 返回非国内 ip 则 drop_resp
  - tag: query_is_local_ip
    type: sequence
    args:
      - exec: $local_sequence
      - matches: "!resp_ip $geoip_cn"
        exec: drop_resp

  # fallback 用远程服务器 sequence
  - tag: query_is_remote
    type: sequence
    args:
      - exec: $remote_sequence

  # fallback 用远程服务器 sequence
  - tag: fallback
    type: fallback
    args:
      primary: query_is_local_ip
      secondary: query_is_remote
      threshold: 500
      always_standby: true

  # 查询国内域名
  - tag: query_is_local_domain
    type: sequence
    args:
      - matches: qname $geosite_cn
        exec: $local_sequence

  # 查询国外域名
  - tag: query_is_no_local_domain
    type: sequence
    args:
      - matches: qname $geosite_no_cn
        exec: $remote_sequence

  # 主要的运行逻辑插件
  # sequence 插件中调用的插件 tag 必须在 sequence 前定义,
  # 否则 sequence 找不到对应插件。
  - tag: main_sequence
    type: sequence
    args:
      - exec: $lazy_cache
      - exec: $query_is_local_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_no_local_domain
      - exec: jump has_resp_sequence
      - exec: $fallback

  # 启动 udp 服务器。
  - tag: udp_server
    type: udp_server
    args:
      entry: main_sequence
      listen: ":5335"

  # 启动 tcp 服务器。
  - tag: tcp_server
    type: tcp_server
    args:
      entry: main_sequence
      listen: ":5335"

mosdns 的 log 记录

INFO    unpacking entry {"tag": "cn", "length": 11163, "file": "/var/mosdns/geoip_cn.txt"}
INFO    unpacking entry {"tag": "cn", "length": 65573, "file": "/var/mosdns/geosite_cn.txt"}
INFO    unpacking entry {"tag": "geolocation-!cn", "length": 19224, "file": "/var/mosdns/geosite_geolocation-!cn.txt"}
INFO    unpacking entry {"tag": "category-ads-all", "length": 64548, "file": "/var/mosdns/geosite_category-ads-all.txt"}
INFO    loading plugin  {"tag": "geosite_cn", "type": "domain_set"}
INFO    starting api http server        {"addr": "0.0.0.0:9091"}
INFO    loading plugin  {"tag": "geoip_cn", "type": "ip_set"}
INFO    loading plugin  {"tag": "geosite_no_cn", "type": "domain_set"}
INFO    loading plugin  {"tag": "lazy_cache", "type": "cache"}
INFO    lazy_cache      cache dump loaded       {"entries": 610}
INFO    loading plugin  {"tag": "forward_local", "type": "forward"}
INFO    loading plugin  {"tag": "forward_remote", "type": "forward"}
INFO    loading plugin  {"tag": "local_sequence", "type": "sequence"}
INFO    loading plugin  {"tag": "remote_sequence", "type": "sequence"}
INFO    loading plugin  {"tag": "has_resp_sequence", "type": "sequence"}
INFO    loading plugin  {"tag": "query_is_local_ip", "type": "sequence"}
INFO    loading plugin  {"tag": "query_is_remote", "type": "sequence"}
INFO    loading plugin  {"tag": "fallback", "type": "fallback"}
INFO    loading plugin  {"tag": "query_is_local_domain", "type": "sequence"}
INFO    loading plugin  {"tag": "query_is_no_local_domain", "type": "sequence"}
INFO    loading plugin  {"tag": "main_sequence", "type": "sequence"}
INFO    loading plugin  {"tag": "udp_server", "type": "udp_server"}
INFO    loading plugin  {"tag": "tcp_server", "type": "tcp_server"}
INFO    all plugins are loaded
WARN    forward_remote  upstream error  {"uqid": 1, "qname": "evoke-windowsservices-tas.msedge.net.", "qtype": 1, "qclass": 1, "upstream": "tls://8.8.8.8", "error": "context deadline exceeded"}
WARN    udp_server      entry returned an err   {"query": {"uqid": 1, "client": "::ffff:192.168.16.10", "qname": "evoke-windowsservices-tas.msedge.net.", "qtype": 1, "qclass": 1, "elapsed": "5.001051213s"}, "error": "exchange: context deadline exceeded"}
WARN    udp_server      entry returned an err   {"query": {"uqid": 3, "client": "::ffff:192.168.16.10", "qname": "evoke-windowsservices-tas.msedge.net.", "qtype": 1, "qclass": 1, "elapsed": "5.001378291s"}, "error": "exchange: context deadline exceeded"}
IrineSistiana commented 1 year ago

报错确实是内存问题导致崩溃,但从报错看不出来问题原因。

貌似你使用的 mosdns 是 patch 过的版本。崩溃日志跟这里的 mosdns 的代码和你的配置文件都对应不上。建议先去 op 开发者那里反馈。

lengfwong commented 1 year ago

报错确实是内存问题导致崩溃,但从报错看不出来问题原因。

貌似你使用的 mosdns 是 patch 过的版本。崩溃日志跟这里的 mosdns 的代码和你的配置文件都对应不上。建议先去 op 开发者那里反馈。

不好意思,刚才配置粘错了,remote_sequence插件少了“- exec: nftset inet,fw4,gfwlist,ipv4_addr,32”这一行。注释掉nftable插件后,mosdns重启日志里就正常了,似乎就是这个插件造成的,不过也就是启动的时候出现一次,后续运行正常,能将查询ip加入nftables,不影响使用。 谢谢。