We are using OpenLink Virtuoso as the primary database manager for a NodeJS project. We query the database using SPARQL queries only, through the HTTP SPARQL endpoint. For this, we are using the request-promise library, with the following configuration:
const queryRequest = rp({
method: "POST",
uri: queryObject.fullUrl,
form: {
query: queryObject.query,
maxrows: queryObject.maxRows,
format: queryObject.resultsFormat
},
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
json: true,
forever : true, // Keep connections alive instead of creating new ones
timeout : Config.dbOperationTimeout,
})
.then(function (parsedBody) {
When running our tests, we boot up the application (new express app object and nodejs server) hundreds of times and try to close it cleanly too. The app shuts down, the server also, but I think virtuoso connections stay open, because the number of connections keeps increasing slowly although we are trying to reuse existing connections.
The close() method (which tears down the app) runs these functions:
const closePendingConnections = function(callback)
{
async.map(Object.keys(self.pendingRequests), function(queryID, cb)
{
if(self.pendingRequests.hasOwnProperty(queryID))
{
self.pendingRequests[queryID].cancel(cb) //try to abort all requests in the queue
}
}, callback);
};
const destroyQueue = function(callback)
{
self.q.destroy(callback);
};
After approximately 150 tests (bootups and shutdowns) queries start failing and tests halt. We tried to use a queue to ensure that only a single connection to virtuoso is active for every app bootup at a given time. Printing the number of pending connections shows constantly 0 or 1 request in the queue, so I know it is not the problem of the queue.
Where is a screenshot of the virtuoso profiler after running those tests:
Is there any way to force all HTTP connections to virtuoso to close after every server and app shutdown and before booting it up again (as we have to do this for every test)?