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

.use does not handle synchronous work functions #296

Open
joelrbrandt opened this issue Jul 6, 2022 · 0 comments · May be fixed by #297
Open

.use does not handle synchronous work functions #296

joelrbrandt opened this issue Jul 6, 2022 · 0 comments · May be fixed by #297

Comments

@joelrbrandt
Copy link

If a user accidentally passes a non-Promise-returning function (or a function that throws a synchronous exception) to .use, .use will throw an exception and never release its resource.

One way this came up for me was using .use to access some property on the resource that is a cached value of some recent external state (e.g. statistics from a database server).

For example:

async function getFreeMemory(): Promise<number> {
  const memory = await myPool.use(resource => resource.memory);
  return memory.free;
} 

Calling the above function will throw TypeError: fn(...).then is not a function and the resource will never be released. This happens here.

@joelrbrandt joelrbrandt linked a pull request Jul 6, 2022 that will close this issue
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 a pull request may close this issue.

1 participant