Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

OkHttp retries consume RequestBody streams, causing empty payloads on retry for multipart uploads

Aperta
#9,136 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java, kotlin
Ambito
networking

Direzione di ricerca

Start by reading OkHttp's retry behavior and how multipart RequestBody writes its InputStream; the issue does not name source files or tests. Reproduce the described connection failure with a mock server, then verify that a retry does not send an empty upload body.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

OkHttp version 4.12.0

Description

When retryOnConnectionFailure is enabled (default behavior), OkHttp retries failed requests (e.g., due to connection errors) by reusing the same RequestBody. For multipart uploads using a non-repeatable InputStream (e.g., ByteArrayInputStream), the stream is fully consumed during the first attempt. This results in an empty payload (0-byte file) being sent on retry, leading to data loss or incomplete uploads.

This issue affects scenarios like file uploads where the InputStream cannot be reliably reset (e.g., network streams). Workarounds include disabling retries (retryOnConnectionFailure(false)) but they are not ideal when relying on automatic retries.

A common attempt to fix this is calling InputStream.reset() after marking the stream, but this fails because OkHttp's retry mechanism does not provide a hook to reset the stream between attempts.

Steps to Reproduce
  1. Create an OkHttp client with retryOnConnectionFailure(true) (default).
  2. Prepare a multipart RequestBody using a non-repeatable InputStream (e.g., ByteArrayInputStream).
  3. Send a POST request to a mock server (e.g., via WireMock) that simulates a connection failure on the first attempt (e.g., returns an empty response or fault to trigger retry).
  4. Observe the retry request: The InputStream is exhausted, sending an empty body (0 bytes).
Lingua principale
Kotlin
Stelle
47.1k
Fork
9.3k
Merge medio
18h 18m
PR unite (30g)
15

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lysine-dev/okhttp

Tutte le issue di lysine-dev/okhttp

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.