{"record":{"id":"ccc2e0065286ee4d","repo":"bumptech/glide","slug":"failed-to-connect-or-obtain-data","errorCode":null,"errorMessage":"Failed to connect or obtain data","messagePattern":"Failed to connect or obtain data","errorType":"http","errorClass":"HttpException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java","lineNumber":98,"sourceCode":"      // See http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html.\n      try {\n        if (lastUrl != null && url.toURI().equals(lastUrl.toURI())) {\n          throw new HttpException(\"In re-direct loop\", INVALID_STATUS_CODE);\n        }\n      } catch (URISyntaxException e) {\n        // Do nothing, this is best effort.\n      }\n    }\n\n    urlConnection = buildAndConfigureConnection(url, headers);\n\n    try {\n      // Connect explicitly to avoid errors in decoders if connection fails.\n      urlConnection.connect();\n      // Set the stream so that it's closed in cleanup to avoid resource leaks. See #2352.\n      stream = urlConnection.getInputStream();\n    } catch (IOException e) {\n      throw new HttpException(\n          \"Failed to connect or obtain data\", getHttpStatusCodeOrInvalid(urlConnection), e);\n    }\n\n    if (isCancelled) {\n      return null;\n    }\n\n    final int statusCode = getHttpStatusCodeOrInvalid(urlConnection);\n    if (isHttpOk(statusCode)) {\n      return getStreamForSuccessfulRequest(urlConnection);\n    } else if (isHttpRedirect(statusCode)) {\n      String redirectUrlString = urlConnection.getHeaderField(REDIRECT_HEADER_FIELD);\n      if (TextUtils.isEmpty(redirectUrlString)) {\n        throw new HttpException(\"Received empty or null redirect url\", statusCode);\n      }\n      URL redirectUrl;\n      try {\n        redirectUrl = new URL(url, redirectUrlString);","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/data/HttpUrlFetcher.java#L80-L116","documentation":"HttpUrlFetcher calls connect() and getInputStream() on the HttpURLConnection. If either operation throws an IOException (connection refused, timeout, DNS failure, network unreachable), it is wrapped in an HttpException with the message 'Failed to connect or obtain data'. The HTTP status code is extracted from the connection if available, otherwise INVALID_STATUS_CODE (-1) is used.","triggerScenarios":"Network connectivity is unavailable or unreliable. DNS resolution fails for the image host. The server is down or refusing connections. Connection or read timeout exceeded. SSL/TLS handshake failure.","commonSituations":"Loading images on flaky mobile networks. Loading from a host that is behind a firewall or geo-blocked. Slow servers that exceed Glide's default timeout. HTTPS certificate issues with self-signed or expired certs.","solutions":["Verify network connectivity and that the URL is reachable in a browser or via curl","Increase connection/read timeouts or integrate OkHttp with Glide for finer timeout control","Add .error() and .fallback() placeholders so the UI degrades gracefully","Implement retry logic via a custom RequestListener or RetryExecutor"],"exampleFix":"// before\nGlide.with(context).load(url).into(imageView);\n// after — add error placeholder and longer timeout via OkHttp integration\nGlide.with(context)\n  .load(url)\n  .error(R.drawable.error_placeholder)\n  .into(imageView);","handlingStrategy":"retry","validationCode":"// Check connectivity before attempting image load\nprivate boolean isNetworkAvailable(Context context) {\n  ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);\n  NetworkInfo active = cm.getActiveNetworkInfo();\n  return active != null && active.isConnected();\n}\nif (isNetworkAvailable(context)) {\n  Glide.with(context).load(url).into(imageView);\n}","typeGuard":null,"tryCatchPattern":"Glide.with(context)\n  .load(url)\n  .error(R.drawable.error_placeholder)\n  .listener(new RequestListener<Drawable>() {\n    @Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {\n      // HttpException with 'Failed to connect or obtain data' surfaces here\n      Log.w(TAG, \"Connection failed for \" + model, e);\n      return false;\n    }\n    @Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }\n  })\n  .into(imageView);","preventionTips":["Check network connectivity before loading remote images","Integrate OkHttp with Glide for configurable timeouts and connection pooling","Always provide .error() placeholders for remote loads","Consider implementing exponential backoff retry for transient network failures"],"tags":["glide","http","connection","network"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}