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/pub sub #105

Merged
merged 8 commits into from
Nov 22, 2023
Merged

Fix/pub sub #105

merged 8 commits into from
Nov 22, 2023

Conversation

buntec
Copy link
Contributor

@buntec buntec commented Aug 7, 2023

Attempts to fix #100 and #104.

@buntec buntec marked this pull request as ready for review September 25, 2023 07:02
@lenguyenthanh
Copy link
Member

Thanks, I have the same issue. And this fixed the issue for me.

@armanbilge armanbilge self-requested a review November 20, 2023 03:36
@armanbilge armanbilge closed this Nov 20, 2023
@armanbilge armanbilge reopened this Nov 20, 2023
private class TimeoutConnection[F[_]: Temporal](rC: RedisConnection[F], duration: Duration) extends RedisConnection[F] {

def runRequest(inputs: Chunk[NonEmptyList[ByteVector]], key: Option[ByteVector]): F[Chunk[Resp]] =
rC.runRequest(inputs, key).timeout(duration)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I missed it. What replaces this .timeout(...) call? I don't think I saw any new .timeout(...) calls introduced above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, you are right, will try to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

I took a quick look, and have a naive solution, which is add timeout to request function of each Connection class. Would it work?

M core/shared/src/main/scala/io/chrisdavenport/rediculous/RedisConnection.scala
@@ -40,7 +40,7 @@ object RedisConnection{
       }
     } 
   }
-  private[rediculous] case class PooledConnection[F[_]: Concurrent](
+  private[rediculous] case class PooledConnection[F[_]: Temporal](
     pool: KeyPool[F, Unit, Socket[F]], timeout: Duration
   ) extends RedisConnection[F]{
     def runRequest(inputs: Chunk[NonEmptyList[ByteVector]], key: Option[ByteVector]): F[Chunk[Resp]] = {
@@ -52,6 +52,7 @@ object RedisConnection{
           case _ => Applicative[F].unit
         }
       }.rethrow
+      .timeout(timeout)
     }
   }
 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's what I've done now. I've also sealed the RedisConnection trait to ensure exhaustive matches in RedisPubSub. Or is that going too far?

Copy link
Member

Choose a reason for hiding this comment

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

I've also sealed the RedisConnection trait to ensure exhaustive matches in RedisPubSub. Or is that going too far?

I think that's a good idea.

Copy link
Contributor

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Wouldn't a more straightforward fix be to keep TimeoutConnection, add it to the pattern match, and handle that case recursively?

I think adding sealed is good, but it's a source-breaking change that probably Chris should sign-off on.

If I understand correctly: for the record, this sort of bug would be prevented with proper linting enabled?

@buntec
Copy link
Contributor Author

buntec commented Nov 22, 2023

Agree, that seems better!

@lenguyenthanh
Copy link
Member

If I understand correctly: for the record, this sort of bug would be prevented with proper linting enabled?

I would believe so.

@armanbilge armanbilge merged commit 24314e1 into davenverse:main Nov 22, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants