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

RequestError on multiple parallel queries using one connection #355

Closed
drywolf opened this issue Jan 14, 2016 · 3 comments
Closed

RequestError on multiple parallel queries using one connection #355

drywolf opened this issue Jan 14, 2016 · 3 comments

Comments

@drywolf
Copy link

drywolf commented Jan 14, 2016

Hi,

I'm using tedious to execute simple SQL queries by using one shared connection.
The TDS queries/requests are triggered from an Express.js route, therefore many simultaneous requests could be executing at the same time, if the frequency of the incoming HTTP requests from the client is high enough.

When a HTTP request comes in, while another TDS request is still being handled by tedious, I get this error:
Requests can only be made in the LoggedIn state, not the SentClientRequest state
at RequestError (...\node_modules\tedious\lib\errors.js:42:12)

As long as the TDS requests can complete one after the other before the next HTTP request comes in, this error does not happen (at least that's what I get from the basic trials that I did).

Also, it looks like the people over at sequelize are also experiencing this problem in some way sequelize/sequelize#4105.

Does tedious support queuing multiple requests out of the box, or does this need to be handled by user-code ?
Meaning that if a TDS-request is currently active, is it forbidden to create another Request(sql, (err, count) { ... }) and execute it on the same connection ?

Thanks,
Regards Wolfgang

@drywolf
Copy link
Author

drywolf commented Jan 14, 2016

Sorry, I just realized that this is not supported by design, after I found this issue discussing the same usecase.

... and read the documentation on new Request more carefully ;)

Can someone give some hints though how to properly manage this situation though ?
Should I look at using pekim/tedious-connection-pool or coopernurse/node-pool (like it is done in node-mssql) to get support for multiple concurrent requests.

Thanks

@arthurschreiber
Copy link
Collaborator

Hey @drywolf,

as you seem to have already found out, tedious does not support request queueing out of the box, and the preferred solution is to use a connection pool. You're free to use on of the existing modules or roll your own. 😄

@drywolf
Copy link
Author

drywolf commented Jan 14, 2016

Thanks for the reply.
I already started using tedious-connection-pool in my code and the first tests worked flawlessly, my code is working as expected now.
I hope these comments will help people in the future if they bump into the same question 😄 😉

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

2 participants