Skip to content

Conversation

@Sh4d1
Copy link
Contributor

@Sh4d1 Sh4d1 commented Jan 22, 2026

Fixes #16

When pool.get() is cancelled (via a tokio::time::timeout for instance) while is_recyclable() is running, the object being validated is unconditionally detached from the pool.

This patch introduces a CancellationBehavior option:

  • Detach (default): Detach the object from the pool. This preserves existing behavior.
  • ReturnToPool: Return the object to the pool for potential reuse.

cc @tisonkun

Signed-off-by: Patrik Cyvoct <patrik@ptrk.io>
@Sh4d1 Sh4d1 changed the title Add configurable behavior for cancelled get() calls feat: add configurable behavior for cancelled get() calls Jan 22, 2026
@tisonkun
Copy link
Contributor

Thanks for your contribution @Sh4d1!

The ReturnToPool impl looks really good.

I'm considering always returning the unready object to the pool if is_recyclable is cancelled, since it does no harm the next get would check is_recyclable again.

In this way, we expose less config options to users and reduce the learning burden. I think the most proper manner here is to return the unready_object to the pool.

We may further merge UnreadyObject and Object.

What do you think?

@Sh4d1
Copy link
Contributor Author

Sh4d1 commented Jan 23, 2026

I thought about it, but it really depends on the behaviour of is_recyclable. For my usecase it works, but I was unsure of all the usecase behind it so added it that way to not break anyone's setup!

If you think it's better to return to the pool everytime we can change to that behaviour 😄

@tisonkun
Copy link
Contributor

on the behaviour of is_recyclable

Ah. Correct. Since is_recyclable takes &mut Self::Object, the state can be modified and in an intermediate unready state.

Let's keep the current structure and I'll merge it in this week (ping me if I fail to merge it).

The very last concern from my side is about naming and docs. CancellationBehavior reads too generic but I can't find a better one now.

@Sh4d1
Copy link
Contributor Author

Sh4d1 commented Jan 23, 2026

Yeah I also find the naming a bit generic but couldn't find something else without having like DropBehaviourOnGet which is a bit of a mouthful 😅

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
Copy link
Contributor

@Sh4d1 I chose RecycleCancelledStrategy to be precise and aligned with QueueStrategy naming.

If you're OK with this, I'm going to merge this patch and release a 1.1.0 version to deliever it :D

@Sh4d1
Copy link
Contributor Author

Sh4d1 commented Jan 24, 2026

Perfect ! Works for me 😄 thanks @tisonkun !

@tisonkun tisonkun merged commit b575b1a into fast:main Jan 24, 2026
9 checks passed
@tisonkun
Copy link
Contributor

@Sh4d1 v1.1.0 has been released with this feature included. Feel free to test it out and I'd appreciate it if you can give the feedback :D

@Sh4d1
Copy link
Contributor Author

Sh4d1 commented Jan 24, 2026

Yay! I'll try to bump it next week on our side !

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.

Cancelled get calls forces the pool object to be detached

2 participants