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

ConnectionPools in async code appear to be broken in 6.1.0 #994

Closed
ghost opened this issue Feb 20, 2020 · 4 comments
Closed

ConnectionPools in async code appear to be broken in 6.1.0 #994

ghost opened this issue Feb 20, 2020 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 20, 2020

This is precisely the kind of code that was broken in the update due to this change. I believe this should be listed as either a known bug or as a deliberately deprecated functionality.


const pool = new sql.ConnectionPool(config)
  .connect()
  .then(pool => {
    console.log('New Connection to MSSQL')
    return pool
  }).catch(err => {
    console.log('Database Connection Failed! Bad Config: ', err)
  })

async function dbExecuteQuery(arg){
  const conn = await pool
  const request = new sql.Request(conn)

  if (arg.input) {
    arg.input.forEach(element => {
      request.input(element.name, element.value)
    });
  }

  return request.query(arg.query, arg.input)
  .then(pass=>{
    dbLogQuery(arg, pass)
    return pass
  }).catch(error=>{
    throw error
  })
}

I might write bad code, but it's bad code that worked in 6.0.1.

Originally posted by @Jack-CHS-PWD in #941 (comment)

@ghost
Copy link
Author

ghost commented Feb 20, 2020

When attempting to execute a query, 6.1.0 will return the error "ConnectionError Cannot call write after a stream was destroyed"

Later queries in the same application instance will return the error "RequestError: No connection is specified for that request."

My assumption is that the ConnectionPool is being closed erroneously immediately, leading to the first error, and being garbage collected shortly after, causing the second.

Rolling back to 6.0.1, however, still works as intended.

@dhensby
Copy link
Collaborator

dhensby commented Feb 21, 2020

Hmmm, that's strange, that code looks like it should be fine, there's no code closing the pool, so I'm not sure how you're getting errors.

@dhensby
Copy link
Collaborator

dhensby commented Feb 21, 2020

This looks like a duplicate of #993

@dhensby dhensby closed this as completed Feb 21, 2020
@ghost
Copy link
Author

ghost commented Feb 21, 2020

It was, thank you.

@tediousjs tediousjs locked as resolved and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant