-
-
Notifications
You must be signed in to change notification settings - Fork 470
Improve client timeout options (#2383) #3844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for zio-http ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
72a5d40 to
9d4223f
Compare
9d4223f to
6680b7c
Compare
| .schedule( | ||
| new Runnable { | ||
| override def run(): Unit = { | ||
| AsyncBodyReader.this.synchronized { |
There was a problem hiding this comment.
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?
| val currentTask = timeoutTask.get() | ||
| if (currentTask != null) { | ||
| currentTask.cancel(false) | ||
| timeoutTask.set(null) | ||
| } |
There was a problem hiding this comment.
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.
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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?
| val currentTask = timeoutTask.get() | ||
| if (currentTask != null) { | ||
| currentTask.cancel(false) | ||
| timeoutTask.set(null) | ||
| } |
There was a problem hiding this comment.
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
fixes #2383