{"record":{"id":"056ecf510f3dc076","repo":"2dust/v2rayN","slug":"received-ntp-response-is-too-short","errorCode":null,"errorMessage":"Received NTP response is too short.","messagePattern":"Received NTP response is too short\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"v2rayN/ServiceLib.UdpTest/UdpTestService.cs","lineNumber":142,"sourceCode":"\n                var currentRoundTripTime = stopwatch.Elapsed;\n                if (currentRoundTripTime < roundTripTime)\n                {\n                    roundTripTime = currentRoundTripTime;\n                }\n            }\n            catch\n            {\n                if (attempt == 1 && roundTripTime == TimeSpan.MaxValue)\n                {\n                    throw;\n                }\n            }\n        }\n\n        if ((udpReceiveResult?.Length ?? 0) < 4 + 1 + 4 + 2)\n        {\n            throw new Exception(\"Received NTP response is too short.\");\n        }\n\n        if (udpReceiveResult != null && _udpTest.VerifyAndExtractUdpResponse(udpReceiveResult))\n        {\n            return roundTripTime;\n        }\n        else\n        {\n            throw new Exception(\"Failed to verify and extract UDP response.\");\n        }\n    }\n}\n","sourceCodeStart":124,"sourceCodeEnd":155,"githubUrl":"https://github.com/2dust/v2rayN/blob/e01717d8326a4f5060b335523590c5fda943fe03/v2rayN/ServiceLib.UdpTest/UdpTestService.cs#L124-L155","documentation":"Thrown when the received datagram (udpReceiveResult) is null or shorter than 11 bytes (4+1+4+2). Despite the 'NTP' wording this guard is tester-agnostic; it asserts any reply is long enough to carry a minimal header. A null/short result means both send/receive attempts failed to yield usable data.","triggerScenarios":"After the 2-attempt send/receive loop, udpReceiveResult is null (both attempts threw) or its length is < 11 bytes. The attempt loop only rethrows if attempt==1 AND no successful roundTripTime was recorded, so reaching this check implies attempts failed silently or returned a stub.","commonSituations":"Proxy accepted the UDP relay but the target never replied (e.g. blocked DNS/ NTP/STUN port); reply was lost over UDP; target server unreachable through the proxy; response arrived but was shorter than expected (truncated relay packet); both attempts timed out.","solutions":["Confirm the target host/port is reachable through the proxy (e.g. the default DNS 8.8.8.8:53 must be egress-allowed).","Increase operationTimeout to allow slow UDP replies.","Verify the proxy actually relays UDP to the target (some proxies accept UDP ASSOCIATE but drop outbound UDP).","Try a different tester/target to determine whether the target or the relay path is the problem.","Make the message tester-agnostic (the literal says 'NTP' but applies to DNS/STUN/McBe too) so the cause is not misdiagnosed."],"exampleFix":"// before - misleading 'NTP' label for a generic length check\nif ((udpReceiveResult?.Length ?? 0) < 4 + 1 + 4 + 2)\n{\n    throw new Exception(\"Received NTP response is too short.\");\n}\n\n// after - generic, informative message\nif ((udpReceiveResult?.Length ?? 0) < 4 + 1 + 4 + 2)\n{\n    throw new Exception($\"UDP relay returned no usable reply (length={udpReceiveResult?.Length ?? 0}); target may be blocked or the proxy does not relay UDP.\");\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check reply presence/length before the strict guard\nvar len = udpReceiveResult?.Length ?? 0;\nif (len < 4 + 1 + 4 + 2)\n    throw new Exception($\"UDP relay returned no usable reply (length={len}); target blocked or proxy does not relay UDP.\");","typeGuard":"static bool HasMinReplyLength(byte[] reply, int min) => reply != null && reply.Length >= min;","tryCatchPattern":"try\n{\n    await SendUdpRequestAsync(host, port, timeout);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"too short\"))\n{\n    // both attempts yielded no/short data; target unreachable through proxy\n}","preventionTips":["Confirm the target host/port is egress-allowed through the proxy.","Increase operationTimeout for slow UDP paths.","Try a different tester/target to isolate target vs relay issues.","Note the message literally says 'NTP' but applies to all testers."],"tags":["udp-test","ntp","network","response-validation"],"backgroundTag":null,"analyzedSha":"e01717d8326a4f5060b335523590c5fda943fe03","analyzedAt":"2026-08-13T10:10:23.416Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}