KTOR-9545 Curl: Attach bodyChannel to correct job#5564
Conversation
📝 WalkthroughWalkthroughPropagates the request's call Job through the curl engine, switches cancellation/cleanup registration to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt (1)
398-398: Use a backticked descriptive test name.Please rename this to something like
fun `body channel is cancelled when caller scope is cancelled`()to match the shared test style in this repo.As per coding guidelines "Use descriptive test names in backticks:
describe what is being tested."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt` at line 398, Rename the test function testBodyChannelCancelledWhenCallerScopeIsCancelled to use a backticked descriptive name to match repo style; change the function declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = ... to fun `body channel is cancelled when caller scope is cancelled`() = ... so the test reads as a descriptive sentence and follows the backticked test naming convention (update the function name in ContentTest.kt accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt`:
- Line 398: Rename the test function
testBodyChannelCancelledWhenCallerScopeIsCancelled to use a backticked
descriptive name to match repo style; change the function declaration fun
testBodyChannelCancelledWhenCallerScopeIsCancelled() = ... to fun `body channel
is cancelled when caller scope is cancelled`() = ... so the test reads as a
descriptive sentence and follows the backticked test naming convention (update
the function name in ContentTest.kt accordingly).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0774243b-fd18-42aa-a266-1b48e8b62b60
📒 Files selected for processing (5)
ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlMultiApiHandler.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
6ba8104 to
2809649
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt (1)
398-398: Use a backticked descriptive test name (Line 398).Please rename the new test to backtick style to match the repository test convention.
✏️ Suggested rename
- fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = clientTests(except("Apache5")) { + fun `body channel is cancelled when caller scope is cancelled`() = clientTests(except("Apache5")) {As per coding guidelines:
**/*Test.kt: Use descriptive test names in backticks:describe what is being tested.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt` at line 398, Rename the test function testBodyChannelCancelledWhenCallerScopeIsCancelled to a backticked descriptive Kotlin test name to follow repo conventions; change the declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = clientTests(except("Apache5")) { ... } to use a backticked string identifier (for example: fun `body channel is cancelled when caller scope is cancelled`() = clientTests(except("Apache5")) { ... }), keeping the existing clientTests(...) call and body unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlMultiApiHandler.kt`:
- Around line 253-258: In removeEasyHandle,
processCancelledEasyHandle(easyHandle, cause) can throw and prevent
handler.responseCompletable.completeExceptionally and handler.dispose from
running; wrap processCancelledEasyHandle in a try and move
handler.responseCompletable.completeExceptionally(cause) and handler.dispose()
into a finally block so they always run; also guard
completeExceptionally/dispose with their own minimal try/catch to avoid masking
the original exception. Ensure references to EasyHandle, removeEasyHandle,
processCancelledEasyHandle, and RequestHolder.dispose are used to locate the
changes.
---
Nitpick comments:
In
`@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt`:
- Line 398: Rename the test function
testBodyChannelCancelledWhenCallerScopeIsCancelled to a backticked descriptive
Kotlin test name to follow repo conventions; change the declaration fun
testBodyChannelCancelledWhenCallerScopeIsCancelled() =
clientTests(except("Apache5")) { ... } to use a backticked string identifier
(for example: fun `body channel is cancelled when caller scope is cancelled`() =
clientTests(except("Apache5")) { ... }), keeping the existing clientTests(...)
call and body unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 17afffb9-0314-45aa-a5f8-a939a9d9e052
📒 Files selected for processing (6)
ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlMultiApiHandler.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlRaw.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.kt
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.kt
- ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
2809649 to
a9deee3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt (1)
398-398: Use backtick test naming for this new test function.Please rename the function at Line 398 to a descriptive backtick name to match test-file conventions.
♻️ Suggested rename
- fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = clientTests(except("Apache5")) { + fun `body channel is cancelled when caller scope is cancelled`() = clientTests(except("Apache5")) {As per coding guidelines:
**/*Test.kt: Tests must use descriptive test names in backticks:describe what is being tested.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt` at line 398, Rename the test function testBodyChannelCancelledWhenCallerScopeIsCancelled to use a backtick descriptive name (e.g. `body channel cancelled when caller scope is cancelled`) by changing the declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = clientTests(...) to fun `body channel cancelled when caller scope is cancelled`() = clientTests(...); update any internal references to the function name if present and keep the existing implementation and test registration intact (look for the function symbol testBodyChannelCancelledWhenCallerScopeIsCancelled in ContentTest.kt).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt`:
- Around line 19-24: The loop that polls until timeMark.hasNotPassedNow() uses
yield() causing busy-waiting; replace the tight yield() call with a suspending
delay (e.g., a small fixed delay like 20.milliseconds or delay(50)) inside the
while so the condition() check yields the CPU without spinning. Update the
polling loop that references timeMark.hasNotPassedNow() and condition() to call
delay(...) instead of yield() to prevent CPU burn and stabilize tests.
---
Nitpick comments:
In
`@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt`:
- Line 398: Rename the test function
testBodyChannelCancelledWhenCallerScopeIsCancelled to use a backtick descriptive
name (e.g. `body channel cancelled when caller scope is cancelled`) by changing
the declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() =
clientTests(...) to fun `body channel cancelled when caller scope is
cancelled`() = clientTests(...); update any internal references to the function
name if present and keep the existing implementation and test registration
intact (look for the function symbol
testBodyChannelCancelledWhenCallerScopeIsCancelled in ContentTest.kt).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8e85183b-fa8f-4a78-bccc-31a5fb91f597
📒 Files selected for processing (6)
ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlMultiApiHandler.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlRaw.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.kt
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.kt
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlRaw.kt
a9deee3 to
3c5b5c3
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt (1)
397-399: Use a backticked descriptive name for this new test.Please rename the test at Line 398 to the backticked descriptive style used by project test guidelines.
Suggested rename
- fun testBodyChannelCancelledWhenCallerScopeIsCancelled() = clientTests(except("Apache5")) { + fun `body channel is cancelled when caller scope is cancelled`() = clientTests(except("Apache5")) {As per coding guidelines,
**/*Test.kt: "Use descriptive test names in backticks:describe what is being tested."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt` around lines 397 - 399, The test function named testBodyChannelCancelledWhenCallerScopeIsCancelled should be renamed to a backticked descriptive name per project guidelines; locate the function declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() and change it to use a backticked string, for example fun `body channel is cancelled when caller scope is cancelled`(), keeping the `@Test` annotation and the existing clientTests(...) invocation unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.kt`:
- Around line 397-399: The test function named
testBodyChannelCancelledWhenCallerScopeIsCancelled should be renamed to a
backticked descriptive name per project guidelines; locate the function
declaration fun testBodyChannelCancelledWhenCallerScopeIsCancelled() and change
it to use a backticked string, for example fun `body channel is cancelled when
caller scope is cancelled`(), keeping the `@Test` annotation and the existing
clientTests(...) invocation unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c39f8481-4548-439e-a75c-94fe7d5ab4c3
📒 Files selected for processing (6)
ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlMultiApiHandler.ktktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlRaw.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ContentTest.ktktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
🚧 Files skipped from review as they are similar to previous changes (4)
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlClientEngine.kt
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/CurlProcessor.kt
- ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/utils/WaitUtils.kt
- ktor-client/ktor-client-curl/desktop/src/io/ktor/client/engine/curl/internal/CurlRaw.kt
Subsystem
ktor-client-curl
Motivation
KTOR-9545 Curl: body channel not cancelled when caller scope is cancelled
Solution
Attach
bodyChanneltocallContextinstead ofrequest.executionContext. Add a shared regression test for all engines.