{"record":{"id":"8bfe892fd7fe53ff","repo":"v2rayA/v2rayA","slug":"dns-read-length-via-dispatcher-w","errorCode":null,"errorMessage":"dns read length via dispatcher: %w","messagePattern":"dns read length via dispatcher: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/dns/upstream_stub.go","lineNumber":605,"sourceCode":"\t}\n\tdefer conn.Close()\n\n\t// DNS over TCP: prepend 2-byte length prefix.\n\ttcpMsg := make([]byte, 2+len(packed))\n\ttcpMsg[0] = byte(len(packed) >> 8)\n\ttcpMsg[1] = byte(len(packed))\n\tcopy(tcpMsg[2:], packed)\n\n\t// Send DNS query.\n\tconn.SetWriteDeadline(time.Now().Add(5 * time.Second))\n\tif _, err := conn.Write(tcpMsg); err != nil {\n\t\treturn nil, fmt.Errorf(\"dns write via dispatcher: %w\", err)\n\t}\n\n\t// Read 2-byte length prefix.\n\tconn.SetReadDeadline(time.Now().Add(5 * time.Second))\n\tif _, err := conn.Read(tcpMsg[:2]); err != nil {\n\t\treturn nil, fmt.Errorf(\"dns read length via dispatcher: %w\", err)\n\t}\n\trespLen := int(tcpMsg[0])<<8 | int(tcpMsg[1])\n\tif respLen < 0 || respLen > 65535 {\n\t\treturn nil, fmt.Errorf(\"dns invalid response length: %d\", respLen)\n\t}\n\n\t// Read full DNS response.\n\trespData := make([]byte, respLen)\n\ttotalRead := 0\n\tfor totalRead < respLen {\n\t\tn, err := conn.Read(respData[totalRead:])\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"dns read data via dispatcher: %w\", err)\n\t\t}\n\t\ttotalRead += n\n\t}\n\n\trtt := time.Since(start)","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/v2rayA/v2rayA/blob/71e5442fc548c05680ee55eae943e6c0afe9ac51/core/dns/upstream_stub.go#L587-L623","documentation":"Raised in exchangeViaDispatcher when reading the 2-byte TCP length prefix of the DNS response from the dispatcher connection fails — the upstream/route closed the connection or the 5s read deadline expired before the response header arrived.","triggerScenarios":"Thrown at core/dns/upstream_stub.go:605 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the DNS query","Check whether the routed outbound actually forwards TCP traffic","Verify the upstream DNS server responds on TCP"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"71e5442fc548c05680ee55eae943e6c0afe9ac51","analyzedAt":"2026-09-05T20:04:37.459Z","contentChangedAt":"2026-09-05T20:04:37.459Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}