Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.LookupSRV: cannot unmarshal DNS message #53556

Closed
halturin opened this issue Jun 26, 2022 · 11 comments
Closed

net.LookupSRV: cannot unmarshal DNS message #53556

halturin opened this issue Jun 26, 2022 · 11 comments

Comments

@halturin
Copy link

halturin commented Jun 26, 2022

What version of Go are you using (go version)?

$ go version
go version go1.17.11 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""                                                                                                                       
GOARCH="amd64"                                                                                                                       
GOBIN=""                                                                                                                             
GOCACHE="/home/taras/.cache/go-build"                                                                                                
GOENV="/home/taras/.config/go/env"                                                                                                   
GOEXE=""                                                                                                                             
GOEXPERIMENT=""                                                                                                                      
GOFLAGS=""                                                                                                                           
GOHOSTARCH="amd64"                                                                                                                   
GOHOSTOS="linux"                                                                                                                     
GOINSECURE=""                                                                                                                        
GOMODCACHE="/home/taras/devel/go/pkg/mod"                                                                                            
GONOPROXY=""                                                                                                                         
GONOSUMDB=""                                                                                                                         
GOOS="linux"                                                                                                                         
GOPATH="/home/taras/devel/go"                                                                                                        
GOPRIVATE=""                                                                                                                         
GOPROXY="https://proxy.golang.org,direct"                                                                                            
GOROOT="/nix/store/b8ww4577m4q42h9kbdmghfwpp5wz79xf-go-1.17.11/share/go"                                                             
GOSUMDB="sum.golang.org"                                                                                                             
GOTMPDIR=""                                                                                                                          
GOTOOLDIR="/nix/store/b8ww4577m4q42h9kbdmghfwpp5wz79xf-go-1.17.11/share/go/pkg/tool/linux_amd64"                                     
GOVCS=""                                                                                                                             
GOVERSION="go1.17.11"                                                                                                                
GCCGO="gccgo"                                                                                                                        
AR="ar"                                                                                                                              
CC="gcc"                                                                                                                             
CXX="g++"                                                                                                                            
CGO_ENABLED="1"                                                                                                                      
GOMOD="/home/taras/devel/go/src/github.com/ergo-services/ergo/go.mod"                                                                
CGO_CFLAGS="-g -O2"                                                                                                                  
CGO_CPPFLAGS=""                                                                                                                      
CGO_CXXFLAGS="-g -O2"                                                                                                                
CGO_FFLAGS="-g -O2"                                                                                                                  
CGO_LDFLAGS="-g -O2"                                                                                                                 
PKG_CONFIG="pkg-config"                                                                                                              
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1309803719=/tmp/go-build -gno-record-gcc-switches"

What did you do?

	_, srv, err := net.LookupSRV("cloud", "dist", "ergo.services")
	if err != nil {
		return nil, err
	}

What did you expect to see?

resolved SRV records

What did you see instead?

lookup ergo.services on 192.168.88.1:53: cannot unmarshal DNS message

at the same time if I checkout SRV records using dig it shows the correct result

$ dig srv _cloud._dist.ergo.services                                           
                                                                                  
; <<>> DiG 9.18.3 <<>> srv _cloud._dist.ergo.services                             
;; global options: +cmd                                                           
;; Got answer:                                                                    
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51027                         
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0              
                                                                                  
;; QUESTION SECTION:                                                              
;_cloud._dist.ergo.services.    IN      SRV                                       
                                                                                  
;; ANSWER SECTION:                                                                
_cloud._dist.ergo.services. 1600 IN     SRV     10 10 4411 cloud01.ergo.services. 
_cloud._dist.ergo.services. 1600 IN     SRV     10 10 4411 cloud02.ergo.services. 
_cloud._dist.ergo.services. 1600 IN     SRV     10 10 4411 cloud03.ergo.services. 

;; Query time: 2 msec
;; SERVER: 192.168.88.1#53(192.168.88.1) (UDP)
;; WHEN: Sun Jun 26 16:36:18 CEST 2022
;; MSG SIZE  rcvd: 133
@halturin halturin changed the title cannot unmarshal DNS message net.LookupSRV: cannot unmarshal DNS message Jun 26, 2022
@seankhliao
Copy link
Member

can't reproduce that
please run with GODEBUG=netdns=2 and show the output
and also the get the response packet with drill -w output.txt SRV _cloud._dist.ergo.services

@halturin
Copy link
Author

halturin commented Jun 26, 2022

@seankhliao thanks for reply
output of drill command

;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 21960                                 
;; flags: qr rd ra ; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0                    
;; QUESTION SECTION:                                                                     
;; _cloud._dist.ergo.services.  IN      SRV                                              
                                                                                         
;; ANSWER SECTION:                                                                       
_cloud._dist.ergo.services.     1800    IN      SRV     10 10 4411 cloud01.ergo.services.
_cloud._dist.ergo.services.     1800    IN      SRV     10 10 4411 cloud02.ergo.services.
_cloud._dist.ergo.services.     1800    IN      SRV     10 10 4411 cloud03.ergo.services.
                                                                                         
;; AUTHORITY SECTION:                                                                    
                                                                                         
;; ADDITIONAL SECTION:                                                                   
                                                                                         
;; Query time: 193 msec                                                                  
;; SERVER: 8.8.8.8                                                                       
;; WHEN: Sun Jun 26 17:43:42 2022                                                        
;; MSG SIZE  rcvd: 167                                                                   

here is output.txt

; 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19                      
;-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                      
 55 c8 81 80 00 01 00 03 00 00 00 00 06 5f 63 6c 6f 75 64 05    ;          1-  20 
 5f 64 69 73 74 04 65 72 67 6f 08 73 65 72 76 69 63 65 73 00    ;         21-  40 
 00 21 00 01 c0 0c 00 21 00 01 00 00 07 08 00 1d 00 0a 00 0a    ;         41-  60 
 11 3b 07 63 6c 6f 75 64 30 31 04 65 72 67 6f 08 73 65 72 76    ;         61-  80 
 69 63 65 73 00 c0 0c 00 21 00 01 00 00 07 08 00 1d 00 0a 00    ;         81- 100 
 0a 11 3b 07 63 6c 6f 75 64 30 32 04 65 72 67 6f 08 73 65 72    ;        101- 120 
 76 69 63 65 73 00 c0 0c 00 21 00 01 00 00 07 08 00 1d 00 0a    ;        121- 140 
 00 0a 11 3b 07 63 6c 6f 75 64 30 33 04 65 72 67 6f 08 73 65    ;        141- 160 
 72 76 69 63 65 73 00                                                             

run with GODEBUG=netdns=2

❯❯❯❯ GODEBUG=netdns=2 go run .                                                                                               
go package net: dynamic selection of DNS resolver                                                                            
go package net: hostLookupOrder(localhost) = cgo                                                                             
go package net: hostLookupOrder(localhost) = cgo                                                                             
2022/06/26 17:46:01 WARNING! can't resolve cloud nodes: lookup ergo.services on 192.168.88.1:53: cannot unmarshal DNS message
go package net: hostLookupOrder(localhost) = cgo                                                                             
go package net: hostLookupOrder(localhost) = cgo                                                                             
go package net: hostLookupOrder(localhost) = cgo                                                                             
go package net: hostLookupOrder(localhost) = cgo                                                                             
go package net: hostLookupOrder(localhost) = cgo                                                                             
2022/06/26 17:46:01 WARNING! can't resolve cloud nodes: lookup ergo.services on 192.168.88.1:53: cannot unmarshal DNS message

@halturin
Copy link
Author

halturin commented Jun 26, 2022

here is the captured response using wireshark (request made by golang) which could not be parsed by golang.

image

@seankhliao
Copy link
Member

can you try it with GODEBUG=netdns=go+2? I think the parser should be able to handle the message

@halturin
Copy link
Author

the same

❯❯❯❯ GODEBUG=netdns=go+2 go run .                                                                                             
go package net: GODEBUG setting forcing use of Go's resolver                                                                  
go package net: hostLookupOrder(localhost) = files,dns                                                                        
go package net: hostLookupOrder(localhost) = files,dns                                                                        
2022/06/26 18:16:26 WARNING! can't resolve cloud nodes: lookup ergo.services on 192.168.88.1:53: cannot unmarshal DNS message 
go package net: hostLookupOrder(localhost) = files,dns                                                                        
go package net: hostLookupOrder(localhost) = files,dns                                                                        
go package net: hostLookupOrder(localhost) = files,dns                                                                        
go package net: hostLookupOrder(localhost) = files,dns                                                                        
go package net: hostLookupOrder(localhost) = files,dns                                                                        
2022/06/26 18:16:26 WARNING! can't resolve cloud nodes: lookup ergo.services on 192.168.88.1:53: cannot unmarshal DNS message 

@seankhliao
Copy link
Member

can you try modifying the errors in https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/net/lookup.go;l=703;drc=416c953960a475b7418b5c6aef0f46dd102b9129;bpv=1;bpt=1 to return the underlying error and rerun it?

@halturin
Copy link
Author

halturin commented Jun 26, 2022

https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/net/lookup.go;l=739;drc=416c953960a475b7418b5c6aef0f46dd102b9129
this function returns error: Target: compressed name in SRV resource data

to be specific, the problem seems here https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/vendor/golang.org/x/net/dns/dnsmessage/message.go;l=2497;drc=416c953960a475b7418b5c6aef0f46dd102b9129

if _, err := target.unpackCompressed(msg, off, false /* allowCompression */); err != nil {
		return SRVResource{}, &nestedError{"Target", err}
	}

if i change allowCompression to 'true' it works

@seankhliao
Copy link
Member

Duplicate of #36718

@seankhliao seankhliao marked this as a duplicate of #36718 Jun 26, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2022
@halturin
Copy link
Author

Can't you please elaborate on the reason instead of just closing it by marking it as a duplicate?

@seankhliao
Copy link
Member

your DNS server at 192.168.88.1 is returning non conformant responses, SRV targets should not be compressed according to the RFC that introduced then.
The drill output you gave above used a different server (8.8.8.8)

@halturin
Copy link
Author

Thanks a lot.

@golang golang locked and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants