Skip to content

Fix TypeError: Cannot read properties of undefined (reading 'isActive') #881

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

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/pool/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class Pool {
const key = address.asKey()
const pool = this._pools[key]

if (pool && poolState.isActive()) {
if (pool && poolState && poolState.isActive()) {
// there exist idle connections for the given key
if (!this._validate(resource)) {
if (this._log.isDebugEnabled()) {
Expand Down
46 changes: 46 additions & 0 deletions packages/bolt-connection/test/pool/pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,52 @@ describe('#unit Pool', () => {
expect(r1.destroyed).toBeFalsy()
})

it('people are strange', async () => {
let counter = 0
const address = ServerAddress.fromUrl('bolt://localhost:7687')
const pool = new Pool({
create: (server, release) =>
Promise.resolve(new Resource(server, counter++, release)),
destroy: res => {
res.destroyed = true
return Promise.resolve()
},
config: new PoolConfig(2, 500)
})

// Acquire resource
const r0 = await pool.acquire(address)
expect(pool.has(address)).toBeTruthy()
expect(r0.id).toEqual(0)

// Purging the key
await pool.purge(address)
expect(pool.has(address)).toBeFalsy()
expect(r0.destroyed).toBeFalsy()

// Acquiring second resource should recreate the pool
const r1 = await pool.acquire(address)

const r2 = pool.acquire(address)


setTimeout(async () => {
pool._poolState = {}
await r0.close()
}, 700)


try {
await r2
expect(false).toBeTruthy()
} catch(e) {
expect(e.message).toEqual('Connection acquisition timed out in 500 ms. Pool status: Active conn count = 2, Idle conn count = 0.')
}

await r1.close()
await pool.close()
})

it('close purges all keys', async () => {
let counter = 0

Expand Down