Failed HEAD request drops Retry-After and the error code and message

Open Beginner friendly
#247 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
api, networking

Research direction

Start in httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/B2WebApiHttpClientImpl.java: read the non-200 else branch in head() around line 178 and compare it with the POST path at line 286, extractExceptionFromErrorResponse, and getRetryAfterSecondsOrNull (around lines 303-314). Make HEAD failures carry the error code, message and Retry-After the way POST does. Done when a mocked 503 with Retry-After: 7 on a HEAD yields getRetryAfterSecondsOrNull() of 7 and a populated error code and message.

Written by the indexing model from the issue text.

Description

What happens

When B2WebApiHttpClientImpl.head() gets a status other than 200, it throws B2Exception.create(null, statusCode, null, ""). The error has no code and an empty message, and the Retry-After header is ignored, so a 429 or 503 on a HEAD request is retried with the default delay rather than the server's. The POST path keeps all of these.

Where

httpclient/src/main/java/com/backblaze/b2/client/webApiHttpClient/B2WebApiHttpClientImpl.java:178 (head); compare :286 and :303-314 (getRetryAfterSecondsOrNull) used by the POST path.

Why it matters

Impact: Wrong request or result (a poorer error and wrong retry delay), loud. Severity: High, because it happens on every failed HEAD request (normal path for errors), and there is no workaround besides reading the status code from the exception.

How to check

Found by reading the code, not reproduced. Read the else branch in head() and compare it with extractExceptionFromErrorResponse. A test with a mock HTTP client returning 503 with Retry-After: 7 on a HEAD should show getRetryAfterSecondsOrNull() as null.

Version

Seen at v6.5.0. Present on the default branch: present.

Dominant language
Java
Stars
103
Forks
23
Avg merge
5d 8h
Merged PRs (30d)
3

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Backblaze/b2-sdk-java

All issues in Backblaze/b2-sdk-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.