tarn.js icon indicating copy to clipboard operation
tarn.js copied to clipboard

Feature request: Ability to disable reaping

Open EmilIvanov opened this issue 5 years ago • 5 comments

pool.check()-ing on an interval / timeout, in the context of AWS Lambda, doesn't work as the run time gets frozen, leading to issues like https://github.com/knex/knex/issues/3636.

A possible solution to the above may be having the ability to disable reaping (e.g. reapIntervalMillis: false, or disableReaping: true) and do manual pool.check()-ing.

EmilIvanov avatar Sep 25 '20 08:09 EmilIvanov

pool.check()-ing on an interval / timeout, in the context of AWS Lambda, doesn't work as the run time gets frozen, leading to issues like

Could you point to the docs, which describes that AWZ Lambda timefreeze functionality? I don't understand how Lambda could know that it can freeze an app which has timers running and how that affects to the app when it gets unfreezed (are all the timers triggering in the same moment or what) 🤔

Also I don't thing that issue https://github.com/knex/knex/issues/3636 can be caused from that, because reaping has nothing to do with the fact that connections are broken behind the scenes without socket noticing it.

Maybe you are really looking for a manual API to allow emptying all connections from pool which are not leased at the moment?

Please try to explain your issue exactly and how this feature would actually solve it?

elhigu avatar Sep 25 '20 11:09 elhigu

Thank you for the quick response.

Here's some context regarding Lambda: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/

I didn't mean that the knex issue was caused by the reaping, sorry if it "sounded" that way.

The issue is (not specific to this package, but this package can solve it):

  1. Execute Lambda - a connection is created (and an interval is set)
  2. Lambda exists and gets frozen (so is the interval)
  3. Wait for the "close idle client connections timeout" configured on the server - the connection is closed, Lambda is frozen, so on its end is kept open
  4. Run Lambda again - Lambda is unfrozen (so is the interval, but it never got to do a check)
  5. Then this happens - https://github.com/knex/knex/issues/3636

A simple solution is to call pool.check() manually every time Lambda gets unfrozen (which can be done with the current state of this package).

What I want out of this feature request is to be able to opt-out of automatic checking on an interval.

EmilIvanov avatar Sep 25 '20 11:09 EmilIvanov

I think allowing user to explicitly call an extra reaping cycle would be a good idea. Otherwise it really might not happen soon enough that those broken connections would be discarded (if there are too many other timers, that needs to be ran just after unfreeze).

Though I don't see any advantage of disabling the reaping interval completely.

elhigu avatar Nov 12 '20 08:11 elhigu

@EmilIvanov Would you like to send a PR that would add support for invoking reaping cycle manually?

kibertoad avatar Jan 16 '21 22:01 kibertoad

I'm actually working on partial rewrite and might fix this at the same time.

elhigu avatar Jan 17 '21 10:01 elhigu