Comments (11)
It is behaving as documented.
TryAcquire is the same as Acquire except it returns ErrNotAvailable if the pool is at maximum capacity and no resources are available.
You can use provided context to limit how long to wait. (e.g. with https://pkg.go.dev/net#Dialer.DialContext)
from puddle.
I expected the tcp network to remain blocked for 5 seconds, but TryAquirue would return immediately for whatever reason.
from puddle.
So that would be something like always return immediately if nothing is immediately available but start a background acquire if there is room in the pool. Hopefully, the resource would be available next time around. Maybe even return different errors to distinguish between pool is empty and cannot grow and starting a background acquire.
That could be a reasonable change. But @ajjensen13 added this feature just a little over a month ago. I'd like to get their opinion if possible.
from puddle.
I don't have a strong opinion either way.
Although, whether or not the constructor blocks, and for how long, is outside the control of this library. Which makes it feel out of place to code around the assumption that a constructor blocks.
I have no opposition to the proposal. But, might suggest investigating a wrapper function that calls TryAcquire in a go-routine to handle this specific case
from puddle.
The main reason is that the current resource management is synchronous. If we need to implement TryAcquire, it is non-blocking in any situation. We need to complete the creation of resources in the goroutine, and automatically create supplements if the resources are insufficient. If there are free resources, return immediately. If the total number of resources is zero, TryAcquire immediately returns the reason why the resource is unavailable or the last resource creation failed.
from puddle.
I created PR #15 that implements most of what we have discussed. The only thing I didn't do was separate errors for why the TryAcquire
failed. There was some ambiguity regarding what error message would be appropriate in certain circumstances. These can be added later if necessary.
Let me know if this works for everyone.
from puddle.
Thank you for your PR, this PR can meet my needs and it is great. But repeatedly calling TryAcquire may cause the resources in the pool to exceed the maximum number, and we can think about how to return an error.
from puddle.
But repeatedly calling TryAcquire may cause the resources in the pool to exceed the maximum number,
🤦 Wow. Can't believe I missed that. I guess that's why it's helpful to have some eyes on concurrent code. Just pushed a fix that should prevent the pool from overfilling.
from puddle.
I reviewed the code and I think there is no problem, thank you.
from puddle.
Hello, may I ask, when can you merge the PR into the master branch?
from puddle.
Done. I wanted to wait a few days to see if anyone else wanted to comment / review and to give myself a chance to look at it with fresh eyes. It still appeared correct to me. Merged and tagged v1.2.1
.
from puddle.
Related Issues (13)
- Problem with function Close() HOT 1
- Non-blocking version of Acquire HOT 1
- ctx done
- The function Acquire does not return immediately,when ctx Done() HOT 4
- Generics support
- Call to Close() hangs HOT 3
- Recent commit in puddle requires 1.19 while pgx is still on 1.18 HOT 11
- question: How to automatically delete outdated resources? HOT 3
- Undefined: atomic.Int64
- Question: are you ok if we add the possibility to resize the max pool size? HOT 4
- Release 1.1.2? HOT 1
- Deadlock in CreateResource if pool was closed during resource acquisition HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from puddle.