Comments (13)
I got a similar issue. I fixed it in my by providing a call back in the connection:
ConnectionPool.prototype.release = function(connection, callback)
I think this would be a useful feature in the API. Can we add it?
from tedious-connection-pool.
While 50 dollar is not much, I did put up a bonus which is yours if you can provide me with a worked out example of how to do that. Pardon my noob status. I come from Microsoft land... so what you describe is just not yet in my grasp.
To claim reward please find this: https://www.bountysource.com/issues/34547563-failed-to-connect
If you have some example please mail to [email protected]
Thank you very much
from tedious-connection-pool.
@PeterNierop, will you please provide example code?
from tedious-connection-pool.
@bachvudao, how would this work? The connection is released immediately. Callback are only needed for asynchronous operations. Please provide examples of how this works and what problem it solves.
from tedious-connection-pool.
@PeterNierop, what version of tedious-connection-pool are you using? This looks like a bug that was fixed last October.
from tedious-connection-pool.
Sorry for asking, How do I use that callback? I am looking for something that allows me to catch the lost connection.
var Connection = require('tedious').Connection,
Request = require('tedious').Request,
TYPES = require('tedious').TYPES,
config = {
userName: 'sa',
password: 'as',
server: '172.16.252.90',
options : {
debug : {
packet : false,
data : false,
payload: false, //true,
token : false,
log : true
},
connectTimeout:5000,
database: 'test',
encrypt : false
}
},
runner = setInterval(() => {
var connection = new Connection(config)
.on('connect', (err) => {
if (err) {
console.error(err);
} else {
var request = new Request('hh.SomeStoredProcedure', (err) => {
connection.close();
if (err) {
console.error(err);
return;
}
}).on('returnValue', (parameterName, value, metadata) => {
console.log(parameterName + ' = ' + value.length);
});
var bin = new Buffer(8);
request.addParameter('iid', TYPES.Int, 1);
request.addOutputParameter('res', TYPES.VarBinary, bin, {length: 8000});
connection.callProcedure(request);
}
});
}, 1000);
Thank you
Shutting down the SQL server will invoke the same error.
from tedious-connection-pool.
@PeterNierop, please fix the formatting on your example. I'm not going to try to figure it out in it's current state.
To answer your question, you can catch errors by subscribing to the error event on the pool. The example main example in the README.md shows how to do this.
The err parameter of acquire only handled errors specifically related to acquiring the connection, not other connection errors (which can happen at anytime, event after acquiring).
from tedious-connection-pool.
Latest latest. That seems at least the case since I started this project in February. And I most certainly updated several times.
from tedious-connection-pool.
When you can, please use the website (rather than email) to post a clean example.
from tedious-connection-pool.
Hi @ben-page,
So my scenario is like this:
- I have a list of insert I'd like to execute. So I used the pool to execute them all. When all inserts are done, I would like to drain the pool.
- When each request finishes, I'd release the connection like below:
var request = new Request("....", function (err) {
if (err) {
logger.error("Error while inserting row: %s.", err);
} else {
logger.info("Finished request ");
}
connection.release();
subject.next(0);
});
The subject var is a Rx subject.
- To know when all my requests are done, I just subscribe to the Rx subject and drain the pool:
subject.take(requests.length).subscribe(
function (x) { },
function (err) { },
function () {
logger.info("Processed all %s requests. Closing connection pool.", requests.length);
pool.drain();
});
Doing this is giving me an error like below:
Tedious-Connection-Pool: draining pool
Tedious-Connection-Pool: connection ended: 40
Tedious-Connection-Pool: connection ended: 39
Tedious-Connection-Pool: connection ended: 38
Tedious-Connection-Pool: connection ended: 37
Tedious-Connection-Pool: connection ended: 36
Tedious-Connection-Pool: connection ended: 35
Tedious-Connection-Pool: connection ended: 34
Tedious-Connection-Pool: connection ended: 33
Tedious-Connection-Pool: connection ended: 32
Tedious-Connection-Pool: connection ended: 31
Tedious-Connection-Pool: connection ended: 30
Tedious-Connection-Pool: connection ended: 29
Tedious-Connection-Pool: connection ended: 28
Tedious-Connection-Pool: connection ended: 27
Tedious-Connection-Pool: connection ended: 26
Tedious-Connection-Pool: connection ended: 25
Tedious-Connection-Pool: connection ended: 24
Tedious-Connection-Pool: connection ended: 23
Tedious-Connection-Pool: connection ended: 22
Tedious-Connection-Pool: connection ended: 21
Tedious-Connection-Pool: connection ended: 20
Tedious-Connection-Pool: connection ended: 19
Tedious-Connection-Pool: connection ended: 18
Tedious-Connection-Pool: connection ended: 17
Tedious-Connection-Pool: connection ended: 16
Tedious-Connection-Pool: connection ended: 15
Tedious-Connection-Pool: connection ended: 14
Tedious-Connection-Pool: connection ended: 13
Tedious-Connection-Pool: connection ended: 12
Tedious-Connection-Pool: connection ended: 11
Tedious-Connection-Pool: connection ended: 10
Tedious-Connection-Pool: connection ended: 9
Tedious-Connection-Pool: connection ended: 8
Tedious-Connection-Pool: connection ended: 7
Tedious-Connection-Pool: connection ended: 6
Tedious-Connection-Pool: connection ended: 5
Tedious-Connection-Pool: connection ended: 4
Tedious-Connection-Pool: connection ended: 3
Tedious-Connection-Pool: connection ended: 2
Tedious-Connection-Pool: connection ended: 1
Tedious-Connection-Pool: connection closing because of error
2016-06-15 09:33:45.604 Could not connect to db ConnectionError: Connection lost - This socket is closed.
I think this error is because the pool is draining while some connection has not finished yet. By adding the callback, I can now do:
connection.release(function () {
subject.next(0);
});
The problem does go away for me after this. Let me know if you think there is a better way to do this.
from tedious-connection-pool.
@PeterNierop, your example doesn't seem to be using tedious-connection-pool
at all. It's creating the connections directly.
I did fix a condition where TypeError: Cannot read property 'close' of undefined
could be thrown. But I don't know if this solved your entire problem. If not, please post a complete example, including creating the pool, acquiring the connection, and releasing the connection.
from tedious-connection-pool.
@bachvudao, passing a callback to release()
does nothing. It will never be executed.
from tedious-connection-pool.
We also saw this issue recently and it causes a server crash because the exception could not be handled. Will there be a new release of tedious-connection-pool that contains this fix?
from tedious-connection-pool.
Related Issues (20)
- Update memory-usage test to add validation. HOT 2
- Error: Acquire Timeout Exceeded for queued queries. HOT 6
- error thrown in tedious-connection-pool when calling release() HOT 2
- Acquire calls do not timeout if pool is drained.
- Support tedious 2.0.1? HOT 3
- Allow prepared statements to persist across returning a connection to the pool HOT 2
- new maintainer ? HOT 4
- Multiple Request On Multiple Connection HOT 1
- Error: connection.release is not a function HOT 1
- Incompatibility with Rollup HOT 1
- ConnectionError: Failed to connect to <server name> in 15000ms
- 1.0.5 release may be incompatible with tedious 5.x release HOT 1
- Pause()/resume() doesn't work as expected with connection from connectionPool
- Pool fills up with 'USED' connections - node app restart required as a result HOT 1
- Timeouts don't seem to work as expected
- Draining the pool after releasing connections may cause write to destroyed stream HOT 3
- TypeError: cb is not a function HOT 2
- Is this project dead? HOT 7
- request.transformIntoExecuteSqlRpc() is not a function HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tedious-connection-pool.