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

About the acquire function in pool.js #212

Open
dbxiaoqiang opened this issue Nov 21, 2017 · 1 comment
Open

About the acquire function in pool.js #212

dbxiaoqiang opened this issue Nov 21, 2017 · 1 comment
Assignees
Labels

Comments

@dbxiaoqiang
Copy link

dbxiaoqiang commented Nov 21, 2017

hello, I have a question about these codes.
pool.js

acquire(priority) {
    if (this._started === false && this._config.autostart === true) {
            this.start()
    }
    if (this._draining) {
            return this._Promise.reject(
                new Error('pool is draining and cannot accept work')
            )
     }
}

In this function the pool is started but if the pool had been drained the pool's status is still drained
Perhaps it will be a issue. I think if the pool has been drained then it will never be acquired.

@sandfox sandfox self-assigned this Nov 21, 2017
@sandfox sandfox added the bug label Nov 21, 2017
@sandfox
Copy link
Collaborator

sandfox commented Nov 21, 2017

inside start() there is check to stop a "draining" pool from "starting" again https://github.com/coopernurse/node-pool/blob/master/lib/Pool.js#L388:

  start() {
    if (this._draining === true) {
      return;
    }
    if (this._started === true) {
      return;
    }
    this._started = true;
    this._scheduleEvictorRun();
    this._ensureMinimum();
}

so this means in acquire() it will try to start the pool (but not succed), and then the next if statement will cause the method to return a rejected promise.

Does that make sense?

(I have to admit that these internals functions are a little messy and could have better internal interfaces)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants