Closing a partial fixed-length duplex request body does not complete the request side
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #9660 by @Sskift — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- kotlin
- Domain
- backend-api-design
Research direction
Read Exchange.RequestBodySink.close() in okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/connection/Exchange.kt around the linked lines, then trace how complete(...) marks the request side finished. Reproduce the HTTP/2 duplex cancellation sequence described in the issue and check the connection allocation state. Done means closing a partial fixed-length body reports the length mismatch while allowing the cancelled call's connection allocation to be released.
Written by the indexing model from the issue text.
Description
This was observed with OkHttp 5.3.2 while working on https://github.com/ktorio/ktor/pull/5791. The current OkHttp main branch contains the same relevant implementation.
When a fixed-length duplex request is cancelled before all declared bytes are written, closing its sink throws:
ProtocolException: unexpected end of stream
The exception is expected, but the request side is not marked complete, leaving the connection allocated:
connectionCount() == 1
idleConnectionCount() == 0
How to reproduce
The observed sequence is:
- Start an HTTP/2 duplex request whose body returns a positive
contentLength(). - Write only part of the request body and receive the server's final response.
- Cancel the call and close the partially written request sink.
- Observe the length-mismatch exception and that the connection does not become idle.
Exchange.RequestBodySink.close()throws before calling complete(...):
A subsequent close() cannot complete the request because closed is already true.
Should the request side be completed with failure before reporting the length mismatch, so the cancelled call can release its connection allocation?
Workaround
As a workaround in Ktor, after request cancellation we attempt to call flush() before the sink is closed. Because the HTTP/2 stream has already been reset, RequestBodySink.flush() fails and invokes complete(e), which marks the request side complete.
Unfortunately this relies on OkHttp’s internal implementation and only works when flush() fails after cancellation.
- Dominant language
- Kotlin
- Stars
- 47.1k
- Forks
- 9.3k
- Avg merge
- 18h 18m
- Merged PRs (30d)
- 15
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lysine-dev/okhttp
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
lysine-dev/okhttp#9788 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
lysine-dev/okhttp#9761 · 3 comments ·
Maintainers usually reply within 1 day
-
Remove crossinline `addInterceptor` and `addNetworkInterceptor` overloadsMay be free again @Amir-Golmoradi claimed this 9 days ago, and no pull request is open. Openenhancement
Difficulty 3/5 1-2 days Newbie friendliness 58/100
lysine-dev/okhttp#9779 · 1 comment ·
Maintainers usually reply within 1 day
-
HTTP/2 Data padding is not counted toward the connection flow-control window. This deadlocks connections with peers that pad.Possibly taken @Amir-Golmoradi claimed this 5 days ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 67/100
lysine-dev/okhttp#9772 · 6 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
lysine-dev/okhttp#9760 · 3 comments ·
Maintainers usually reply within 1 day
All issues in lysine-dev/okhttp
Similar issues
-
afk-ok area:agents size:S
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
enorm-labs/event-junkie#3523 ·
Maintainers usually reply within 1 day
-
submit-adaption submit-adaption-pre
Difficulty 1/5 Under an hour Newbie friendliness 82/100
BetterAndroid/android-notification-icon-project#750 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
openbase/planetsudo.engine#107 ·
Maintainers usually reply within 1 day
-
native-cpu: -Wreturn-type in skainet_row_threads.c:150 (worker fn has no return)Possibly taken @Doomguy-BFG9000 claimed this today. Opengood first issue size:xs skill:native
Difficulty 1/5 Under an hour Newbie friendliness 78/100
SKaiNET-developers/SKaiNET#1358 · 1 comment ·
Maintainers usually reply within 1 day
-
bug core p3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
RunanywhereAI/runanywhere-sdks#1142 ·
Maintainers usually reply within 1 day