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

Connection is closed with Promise.all #398

Closed
Shockolate opened this issue Dec 29, 2016 · 6 comments
Closed

Connection is closed with Promise.all #398

Shockolate opened this issue Dec 29, 2016 · 6 comments

Comments

@Shockolate
Copy link

I'm finding rampant "Connection is Closed" errors when attempting to paralellize multiple requests using the native Promise.all.

For example if I try to run 4 queries in parallel to SELECT from the same table, the first Request in the Promise.all reports the error.

If I try to run 4 INSERTs requests in parallel into the same table (yes I'm familiar with bulk), the first Request in the Promise.all array reports the error, but the last Request succeeds with insertion (as verified by direct SQL calls to the server).

I believe this bug is related to the Tedious Bug.

@AskYous
Copy link

AskYous commented Mar 7, 2017

I receive this error as well. I only have two requests in my Promise.all but it throws an error saying the connection is closed. This is for a web server but this is my code:

    Promise.all([
      fetch(url + 'costCenters'), // The first SELECT query run on the server
      fetch(url + 'travelPlans') // The seond SELECT query run on the server
    ]).then(function(responses){
      Promise.all(responses.map(function(r){
        return r.json();
      })).then(function(jsons){
        // continue...
      });
    });

But it throws this error:

 { ConnectionError: Connection is closed.
    at D:\home\site\wwwroot\node_modules\mssql\lib\main.js:1569:17
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  name: 'ConnectionError',
  message: 'Connection is closed.',
  code: 'ECONNCLOSED' }

@jmartinez-jobsity
Copy link

jmartinez-jobsity commented Mar 17, 2017

My problem was fixed with #138 (comment)

@Shockolate
Copy link
Author

Shockolate commented Mar 17, 2017

@jmartinez-jobsity I do pass the connection object into the Request constructor, as #138 (comment) suggests.
My issue is doing multiple requests using Promise.all as the title of this issue suggests.

I can't do Promise.all with my wrapper function:

function _connectToDatabase(execute) {
  return new Promise((resolve, reject) => {
    connectionManager.getDatabaseConnection()
    .then(connection => (new sql.Request(connection)))
    .then(execute)
    .then(resolve)
    .catch(error => reject(_sqlErrorParser(error)));
  });
}

@jmartinez-jobsity
Copy link

Weird, cause we are also using Promise.all with a similar approach and it is working

@Shockolate
Copy link
Author

Shockolate commented Mar 20, 2017

@jmartinez-jobsity
Will you provide code samples?

@dhensby
Copy link
Collaborator

dhensby commented Feb 13, 2019

closing as outdated

@dhensby dhensby closed this as completed Feb 13, 2019
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

No branches or pull requests

4 participants