Skip to content

Commit

Permalink
SNOW-792487: Connection pool - pass back error on failed authenticati…
Browse files Browse the repository at this point in the history
…on (snowflakedb#484)

fix error handling for connection pool error
  • Loading branch information
sfc-gh-ext-simba-lb authored May 1, 2023
1 parent 17934c6 commit 6f4b5fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ function Core(options)

// avoid infinite loop if factory creation fails
connectionPool.on('factoryCreateError', function(err) {
const clientResourceRequest = connectionPool._waitingClientsQueue.dequeue();
const clientResourceRequest = connectionPool._waitingClientsQueue.dequeue();
if (clientResourceRequest)
{
clientResourceRequest.reject(err);
}
})

return connectionPool;
Expand Down
41 changes: 34 additions & 7 deletions test/integration/testConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ describe('Connection test - connection pool', function ()
});
});

it('wrong password', function (done)
it('wrong password - use', async function ()
{
var connectionPool = snowflake.createPool(connOption.wrongPwd,
{
Expand All @@ -1093,15 +1093,42 @@ describe('Connection test - connection pool', function ()
assert.equal(connectionPool.min, 1);
assert.equal(connectionPool.size, 1);

// Use the connection pool, automatically creates a new connection
connectionPool.use(async (connection) =>
try
{
assert.ok(connection.isUp(), "not active");
// Use the connection pool, automatically creates a new connection
await connectionPool.use(async (connection) =>
{
assert.ok(connection.isUp(), "not active");
assert.equal(connectionPool.size, 1);
});
}
catch (err)
{
assert.strictEqual(err.message, "Incorrect username or password was specified.");
}
});

it('wrong password - acquire', async function ()
{
var connectionPool = snowflake.createPool(connOption.wrongPwd,
{
max: 10,
min: 1
});

assert.equal(connectionPool.max, 10);
assert.equal(connectionPool.min, 1);
assert.equal(connectionPool.size, 1);

try
{
await connectionPool.acquire();
}
catch (err)
{
assert.strictEqual(err.message, "Incorrect username or password was specified.");
}
});
// no login loop with wrong password
done();
});
});

describe('Heartbeat test', function ()
Expand Down

0 comments on commit 6f4b5fa

Please sign in to comment.