GithubHelp home page GithubHelp logo

使用DOH方式查询DNS,并且DOH服务器经过代理,当有并发DNS查询请求时,第一个DNS查询请求返回结果后,其余DNS查询请求均会失败。 about v2ray-core HOT 11 CLOSED

v2fly avatar v2fly commented on August 16, 2024
使用DOH方式查询DNS,并且DOH服务器经过代理,当有并发DNS查询请求时,第一个DNS查询请求返回结果后,其余DNS查询请求均会失败。

from v2ray-core.

Comments (11)

Loyalsoldier avatar Loyalsoldier commented on August 16, 2024

试一试 VMess 看看会不会有一样的问题?

from v2ray-core.

badO1a5A90 avatar badO1a5A90 commented on August 16, 2024

试一试 VMess 看看会不会有一样的问题?

忘记补充了,已经试过,一样的

from v2ray-core.

badO1a5A90 avatar badO1a5A90 commented on August 16, 2024

试一试 VMess 看看会不会有一样的问题?

v2ray-core/app/dns/dohdns.go 的 282 行 resp, err := s.httpClient.Do(req.WithContext(ctx))

好像是因为一个DNS请求完成时,Dispatched connection关闭,导致了其他并发请求失败
NewDoHNameServer和NewDoHLNameServer的httpClient不同的http.Transport。

我简单把这行改为了

	tr := &http.Transport{
		IdleConnTimeout:   90 * time.Second,
		ForceAttemptHTTP2: true,
		DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
			dest, err := net.ParseDestination(network + ":" + addr)
			if err != nil {
				return nil, err
			}
			conn, err := internet.DialSystem(ctx, dest, nil)
			if err != nil {
				return nil, err
			}
			return conn, nil
		},
	}

	hc := &http.Client{
		Timeout:   time.Second * 180,
		Transport: tr,
	}

	resp, err := hc.Do(req.WithContext(ctx))

这样问题是可以解决的。
但是这样的改法应该是不OK的。

from v2ray-core.

badO1a5A90 avatar badO1a5A90 commented on August 16, 2024

试一试 VMess 看看会不会有一样的问题?

v2ray-core/app/dns/dohdns.go 的 282 行 resp, err := s.httpClient.Do(req.WithContext(ctx))

好像是因为一个DNS请求完成时,Dispatched connection关闭,导致了其他并发请求失败
NewDoHNameServer和NewDoHLNameServer的httpClient不同的http.Transport。

我简单把这行改为了

	tr := &http.Transport{
		IdleConnTimeout:   90 * time.Second,
		ForceAttemptHTTP2: true,
		DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
			dest, err := net.ParseDestination(network + ":" + addr)
			if err != nil {
				return nil, err
			}
			conn, err := internet.DialSystem(ctx, dest, nil)
			if err != nil {
				return nil, err
			}
			return conn, nil
		},
	}

	hc := &http.Client{
		Timeout:   time.Second * 180,
		Transport: tr,
	}

	resp, err := hc.Do(req.WithContext(ctx))

这样问题是可以解决的。
但是这样的改法应该是不OK的。

我傻了,这样就是直连没过代理所以没问题了。。。

from v2ray-core.

badO1a5A90 avatar badO1a5A90 commented on August 16, 2024

原因似乎就是因为一个DNS请求完成时,Dispatched connection关闭,导致了其他并发请求失败了?

重新改了一下
给DoHNameServer加了个dispatcher routing.Dispatcher

type DoHNameServer struct {
	dispatcher routing.Dispatcher
	sync.RWMutex
	ips        map[string]record
	pub        *pubsub.Service
	cleanup    *task.Periodic
	reqID      uint32
	clientIP   net.IP
	httpClient *http.Client
	dohURL     string
	name       string
}

func NewDoHNameServer 中增加了一行

s.dispatcher = dispatcher

282 行 resp, err := s.httpClient.Do(req.WithContext(ctx)) 改成了下方代码

即判断dispatcher是否为空,不为空则是DOH而不是DOHL
DOHL还是原来的处理方式
如果是DOH的话,每个request都是独立的httpClient,就不会因为一个请求完成而中断了connection导致其他的请求失败了。

	hc := s.httpClient

	if s.dispatcher != nil {
		tr := &http.Transport{
			MaxIdleConns:        30,
			IdleConnTimeout:     90 * time.Second,
			TLSHandshakeTimeout: 30 * time.Second,
			ForceAttemptHTTP2:   true,
			DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
				dest, err := net.ParseDestination(network + ":" + addr)
				if err != nil {
					return nil, err
				}

				link, err := s.dispatcher.Dispatch(ctx, dest)
				if err != nil {
					return nil, err
				}
				return net.NewConnection(
					net.ConnectionInputMulti(link.Writer),
					net.ConnectionOutputMulti(link.Reader),
				), nil
			},
		}
		hc = &http.Client{
			Timeout:   time.Second * 180,
			Transport: tr,
		}
	}

	resp, err := hc.Do(req.WithContext(ctx))

这样能解决问题。
但是这样处理看起来似乎有点笨拙。。。

from v2ray-core.

Loyalsoldier avatar Loyalsoldier commented on August 16, 2024

ping @vcptr

from v2ray-core.

darhwa avatar darhwa commented on August 16, 2024

dnsCtx = session.ContextWithMuxPrefered(dnsCtx, true)

你把这行删掉试试还有没有问题?如果没有的话我就提交补丁

from v2ray-core.

badO1a5A90 avatar badO1a5A90 commented on August 16, 2024

dnsCtx = session.ContextWithMuxPrefered(dnsCtx, true)

你把这行删掉试试还有没有问题?如果没有的话我就提交补丁

不行,依然是一堆io: read/write on closed pipe

from v2ray-core.

bbi8 avatar bbi8 commented on August 16, 2024

有客户端1使用远程doh,客户端2不使用远程dns
在客户端1dns解析失败的时候服务端可以看到日志127.0.0.1:60352 accepted tcp:dns.google:443
此时用客户端2下的浏览器访问https://dns.google/dns-query 也是无法打开的,但是访问其他网站没有毛病,服务端日志正常
再同时vps上运行curl https://dns.google/dns-query 也没有问题
感觉问题可能出在服务端而未必是客户端

from v2ray-core.

bbi8 avatar bbi8 commented on August 16, 2024

测试了段时间,可能跟Freedom的"domainStrategy": "UseIP"参数有关,vps上ipv6只是局域网没有公网出口,现在改成UseIPv4,有问题再说

from v2ray-core.

github-actions avatar github-actions commented on August 16, 2024

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days

from v2ray-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.