Skip to content

Conversation

@987Nabil
Copy link
Contributor

@987Nabil 987Nabil commented Dec 8, 2025

fixes #2383

@netlify
Copy link

netlify bot commented Dec 8, 2025

Deploy Preview for zio-http ready!

Name Link
🔨 Latest commit 6680b7c
🔍 Latest deploy log https://app.netlify.com/projects/zio-http/deploys/6936f3c3c31822000892c344
😎 Deploy Preview https://deploy-preview-3844--zio-http.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@987Nabil 987Nabil force-pushed the timeout-client-improvement branch from 72a5d40 to 9d4223f Compare December 8, 2025 15:17
@987Nabil 987Nabil force-pushed the timeout-client-improvement branch from 9d4223f to 6680b7c Compare December 8, 2025 15:50
.schedule(
new Runnable {
override def run(): Unit = {
AsyncBodyReader.this.synchronized {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing (I've actually never seen this syntax before). Maybe just use this.synchronized?

Comment on lines +122 to +126
val currentTask = timeoutTask.get()
if (currentTask != null) {
currentTask.cancel(false)
timeoutTask.set(null)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wrap this in synchronized you can simply use a var for timeoutTask instead of an AtomicReference.

Comment on lines +182 to +211
timeoutMillis.foreach { timeoutMillis =>
val task = ctx
.channel()
.eventLoop()
.schedule(
new Runnable {
override def run(): Unit = {
AsyncBodyReader.this.synchronized {
state match {
case State.Direct(cb) if !readingDone =>
cb.fail(
new IOException(
s"Body read timeout: server stopped sending data after ${timeoutMillis}ms",
),
)
readingDone = true
if (ctx.channel().isOpen) {
ctx.channel().close(): Unit
}
case _ => // Already completed or not connected
}
}
}
},
timeoutMillis,
TimeUnit.MILLISECONDS,
)
timeoutTask.set(task)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same code as above? Maybe extract it all into a method if that's the case?

Comment on lines +238 to +242
val currentTask = timeoutTask.get()
if (currentTask != null) {
currentTask.cancel(false)
timeoutTask.set(null)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is being used everywhere and doesn't have any dependency on the local vals. Maybe extract it into a method to keep things DRY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client does not handle broken servers

2 participants