Skip to content
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

Fix Possible Race Condition #3269

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

scottweaver
Copy link
Contributor

fixes #3268

Refactor 'refreshIdleTimeoutHandler' so that 'ChannelPipeline.replace' does not crash the fiber on unhandled exceptions.

fixes zio#3268

Refactor 'refreshIdleTimeoutHandler' so that 'ChannelPipeline.replace' does not crash the fiber on unhandled exceptions.
Comment on lines +158 to +169
ZIO.attempt {
timeout.map { timeout =>
channel
.pipeline()
.replace(
Names.ReadTimeoutHandler,
Names.ReadTimeoutHandler,
new ReadTimeoutHandler(timeout.toMillis, TimeUnit.MILLISECONDS),
)
}
}.when(channel.isOpen)
.as(channel.isOpen)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This "breaks" the current logic for retrying channels from the pool until we succeed. I think a better solution would be to keep the existing code as is and wrap it in a try-catch block so that we don't fail requests when this happens

  private def refreshIdleTimeoutHandler(
    channel: JChannel,
    timeout: Duration,
  ): Boolean = {
  try {
    channel
      .pipeline()
      .replace(
        Names.ReadTimeoutHandler,
        Names.ReadTimeoutHandler,
        new ReadTimeoutHandler(timeout.toMillis, TimeUnit.MILLISECONDS),
      )
    channel.isOpen
  } catch {
    case _: NoSuchElementException => false
  }

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.

Possible Race Condition in NettyConnectionPool
2 participants