Skip to content

Commit 4df4e02

Browse files
committed
Sending reset if there is a tx going on
1 parent e16cb23 commit 4df4e02

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

packages/core/src/internal/connection-holder.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,16 @@ class ConnectionHolder implements ConnectionHolderInterface {
178178
return this._connectionPromise
179179
}
180180

181+
<<<<<<< HEAD
181182
close (): Promise<null | Connection> {
183+
=======
184+
close(hasTx?: boolean): Promise<void | Connection> {
185+
>>>>>>> Sending reset if there is a tx going on
182186
if (this._referenceCount === 0) {
183187
return this._connectionPromise
184188
}
185189
this._referenceCount = 0
186-
return this._releaseConnection()
190+
return this._releaseConnection(hasTx)
187191
}
188192

189193
/**
@@ -197,7 +201,7 @@ class ConnectionHolder implements ConnectionHolderInterface {
197201
this._connectionPromise = this._connectionPromise
198202
.then((connection?: Connection|null) => {
199203
if (connection != null) {
200-
if (connection.isOpen() && connection.hasOngoingObservableRequests()) {
204+
if (connection.isOpen() && (connection.hasOngoingObservableRequests() || hasTx)) {
201205
return connection
202206
.resetAndFlush()
203207
.catch(ignoreError)

packages/core/src/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ class Session {
494494

495495
this._transactionExecutor.close()
496496

497-
await this._readConnectionHolder.close()
498-
await this._writeConnectionHolder.close()
497+
await this._readConnectionHolder.close(this._hasTx)
498+
await this._writeConnectionHolder.close(this._hasTx)
499499
}
500500
}
501501

packages/core/test/session.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,28 @@ describe('session', () => {
196196
expect(resetAndFlushSpy).toHaveBeenCalledTimes(1)
197197
}, 70000)
198198

199-
it('close should not reset connection if there is not an ongoing request ', async () => {
199+
it('close should not reset connection if there is not an ongoing request', async () => {
200200
const connection = newFakeConnection()
201201
connection.hasOngoingObservableRequests = () => false
202202
const resetAndFlushSpy = jest.spyOn(connection, 'resetAndFlush')
203-
const session = newSessionWithConnection(connection)
203+
const session = newSessionWithConnection(connection, false)
204204

205205
await session.close()
206206

207207
expect(resetAndFlushSpy).not.toHaveBeenCalled()
208208
}, 70000)
209209

210+
it('close should reset connection if there is not an ongoing request but it has tx running', async () => {
211+
const connection = newFakeConnection()
212+
connection.hasOngoingObservableRequests = () => false
213+
const resetAndFlushSpy = jest.spyOn(connection, 'resetAndFlush')
214+
const session = newSessionWithConnection(connection)
215+
216+
await session.close()
217+
218+
expect(resetAndFlushSpy).toHaveBeenCalled()
219+
}, 70000)
220+
210221
it('should close transaction executor', done => {
211222
const session = newSessionWithConnection(newFakeConnection())
212223

0 commit comments

Comments
 (0)