Skip to content

Commit d9bceb4

Browse files
authored
chore: Prevent transaction error (#39279)
1 parent 0d00b05 commit d9bceb4

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

apps/meteor/app/livechat/server/lib/closeRoom.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export async function closeRoom(params: CloseRoomParams, attempts = 2): Promise<
4242
removedInquiryObj = removedInquiry;
4343
} catch (e) {
4444
logger.error({ err: e, msg: 'Failed to close room', afterAttempts: attempts });
45-
await session.abortTransaction();
45+
if (session.inTransaction()) {
46+
await session.abortTransaction();
47+
}
4648
// Dont propagate transaction errors
4749
if (shouldRetryTransaction(e)) {
4850
if (attempts > 0) {
@@ -186,7 +188,7 @@ async function doCloseRoom(
186188
}
187189

188190
const updatedRoom = await LivechatRooms.closeRoomById(rid, closeData, { session });
189-
if (!params.forceClose && (!updatedRoom || updatedRoom.modifiedCount !== 1)) {
191+
if (!params.forceClose && updatedRoom?.modifiedCount !== 1) {
190192
throw new Error('Error closing room');
191193
}
192194

apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ describe('LIVECHAT - rooms', () => {
145145
});
146146
(IS_EE ? it : it.skip)('should prevent create a room for visitor if an app throws an error', async () => {
147147
// this test relies on the app installed by the insertApp fixture
148+
// TODO: this visitor should be created on before block and deleted on after block
148149
const visitor = await createVisitor(undefined, 'visitor prevent from app');
149150
const { body } = await request.get(api('livechat/room')).query({ token: visitor.token });
150151

151152
expect(body).to.have.property('success', false);
152153
await deleteVisitor(visitor.token);
153154
});
154155
it('should create a room for visitor', async () => {
156+
// TODO: this visitor should be created on before block and deleted on after block
155157
const visitor = await createVisitor();
156158
const { body } = await request.get(api('livechat/room')).query({ token: visitor.token });
157159

@@ -164,6 +166,7 @@ describe('LIVECHAT - rooms', () => {
164166
await deleteVisitor(visitor.token);
165167
});
166168
it('should return an existing open room when visitor has one available', async () => {
169+
// TODO: this visitor should be created on before block and deleted on after block
167170
const visitor = await createVisitor();
168171
const { body } = await request.get(api('livechat/room')).query({ token: visitor.token });
169172

@@ -182,6 +185,7 @@ describe('LIVECHAT - rooms', () => {
182185
await deleteVisitor(visitor.token);
183186
});
184187
it('should return a room for the visitor when rid points to a valid open room', async () => {
188+
// TODO: this visitor should be created on before block and deleted on after block
185189
const visitor = await createVisitor();
186190
const room = await createLivechatRoom(visitor.token);
187191
const { body } = await request.get(api('livechat/room')).query({ token: visitor.token, rid: room._id });
@@ -194,6 +198,7 @@ describe('LIVECHAT - rooms', () => {
194198
await deleteVisitor(visitor.token);
195199
});
196200
it('should properly read widget cookies', async () => {
201+
// TODO: this visitor should be created on before block and deleted on after block
197202
const visitor = await createVisitor();
198203
const { body } = await request
199204
.get(api('livechat/room'))

0 commit comments

Comments
 (0)