{"record":{"id":"10b91b73a3814375","repo":"TeamNewPipe/NewPipe","slug":"error-code-io-network-connection-failed","errorCode":"ERROR_CODE_IO_NETWORK_CONNECTION_FAILED","errorMessage":"Too many redirects: {}","messagePattern":"Too many redirects: (.+?)","errorType":"http","errorClass":"HttpDataSourceException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/schabi/newpipe/player/datasource/YoutubeHttpDataSource.java","lineNumber":592,"sourceCode":"                    || httpURLConnectionResponseCode == HttpURLConnection.HTTP_MOVED_PERM\n                    || httpURLConnectionResponseCode == HttpURLConnection.HTTP_MOVED_TEMP\n                    || httpURLConnectionResponseCode == HttpURLConnection.HTTP_SEE_OTHER)) {\n                httpURLConnection.disconnect();\n                final boolean shouldKeepPost = keepPostFor302Redirects\n                        && responseCode == HttpURLConnection.HTTP_MOVED_TEMP;\n                if (!shouldKeepPost) {\n                    // POST request follows the redirect and is transformed into a GET request.\n                    httpMethod = DataSpec.HTTP_METHOD_GET;\n                    httpBody = null;\n                }\n                url = handleRedirect(url, location, dataSpecToUse);\n            } else {\n                return httpURLConnection;\n            }\n        }\n\n        // If we get here we've been redirected more times than are permitted.\n        throw new HttpDataSourceException(\n                new NoRouteToHostException(\"Too many redirects: \" + redirectCount),\n                dataSpecToUse,\n                PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,\n                HttpDataSourceException.TYPE_OPEN);\n    }\n\n    /**\n     * Configures a connection and opens it.\n     *\n     * @param url               The url to connect to.\n     * @param httpMethod        The http method.\n     * @param httpBody          The body data, or {@code null} if not required.\n     * @param position          The byte offset of the requested data.\n     * @param length            The length of the requested data, or {@link C#LENGTH_UNSET}.\n     * @param allowGzip         Whether to allow the use of gzip.\n     * @param followRedirects   Whether to follow redirects.\n     * @param requestParameters parameters (HTTP headers) to include in request.\n     * @return the connection opened","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/TeamNewPipe/NewPipe/blob/9e8be091560a69f35d44bd252eb00bc7911c977b/app/src/main/java/org/schabi/newpipe/player/datasource/YoutubeHttpDataSource.java#L574-L610","documentation":"Thrown by YoutubeHttpDataSource when the open loop follows more redirects than the configured maximum (redirectCount exceeds the maxRedirects cap). It is wrapped as an HttpDataSourceException with cause NoRouteToHostException and ExoPlayer error code ERROR_CODE_IO_NETWORK_CONNECTION_FAILED, type OPEN. This is ExoPlayer's data-source layer for YouTube video playback URLs.","triggerScenarios":"The YouTube /videoplayback URL returns a chain of 3xx responses (301/302/303/307/308) whose hop count exceeds the DataSource's maxRedirects setting before a non-redirect response is received. The makeConnection loop keeps calling handleRedirect until it runs out of allowed hops.","commonSituations":"YouTube CDN rotating between multiple video cache nodes in a loop or a very long chain, a stale/expired playback URL that bounces between redirect endpoints, a misconfigured mirror/proxy that redirects to itself, or a geographically distant client that gets bounced across regional nodes. Also when the itag/URL params have expired and YouTube keeps redirecting to re-signed URLs.","solutions":["Increase the maxRedirects cap on the YoutubeHttpDataSource.Factory so legitimate multi-hop CDN chains can complete.","Refresh the playback URL before playback so it has a fresh signature and does not bounce through re-signing redirects.","Inspect the redirect chain (intermediate Location values) to identify a redirect loop, then fix the source of the loop (e.g. expired params).","If behind a corporate proxy, configure the proxy correctly so YouTube's CDN redirects resolve directly.","Retry playback: transient redirect storms from CDN load balancing often resolve on the next attempt with a freshly resolved URL."],"exampleFix":"// before\nfactory.setMaxRedirects(5);\n// after\nfactory.setMaxRedirects(20);","handlingStrategy":"retry","validationCode":"if (redirectCount > maxRedirects) {\n    // refresh the playback URL before attempting to follow more redirects\n}","typeGuard":null,"tryCatchPattern":"try {\n    dataSource.open(dataSpec);\n} catch (final HttpDataSourceException e) {\n    if (e.getCause() instanceof NoRouteToHostException) {\n        // refresh playback URL and retry once\n    }\n    throw e;\n}","preventionTips":["Configure a generous maxRedirects on the DataSource.Factory to accommodate CDN hop chains.","Use freshly resolved/signed playback URLs to avoid redirect storms from expired params.","Detect redirect loops by tracking visited URLs and bailing early with a clearer error.","Retry playback once with a re-resolved URL before surfacing the failure."],"tags":["network","http","redirect","exoplayer","playback","youtube"],"backgroundTag":null,"analyzedSha":"9e8be091560a69f35d44bd252eb00bc7911c977b","analyzedAt":"2026-08-14T00:11:33.519Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}