Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 10cff5f

Browse files
Log when mutex is acquired and released
1 parent 39c2541 commit 10cff5f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/common/helper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const elasticsearch = require('elasticsearch')
88
const _ = require('lodash')
99
const Joi = require('@hapi/joi')
1010
const { Mutex } = require('async-mutex')
11+
const logger = require('./logger')
1112

1213
AWS.config.region = config.ES.AWS_REGION
1314

@@ -63,9 +64,13 @@ async function getESClient () {
6364
const tId = _.get(params.query, 'transactionId')
6465
params.query = _.omit(params.query, 'transactionId')
6566
if (!tId || tId !== transactionId) {
67+
logger.info(`${transactionId} is trying to acquire the mutex`)
6668
const release = await esClientMutex.acquire()
69+
logger.info(`${transactionId} has acquired the mutex`)
6770
mutexReleaseMap[tId || 'noTransaction'] = release
6871
transactionId = tId
72+
} else {
73+
logger.info(`${transactionId} did not acquire any mutex`)
6974
}
7075
try {
7176
return await esClient.transport.originalRequest(params)
@@ -75,8 +80,12 @@ async function getESClient () {
7580
delete mutexReleaseMap[tId || 'noTransaction']
7681
transactionId = undefined
7782
if (release) {
83+
logger.info(`${transactionId} is now releasing the mutex`)
7884
release()
85+
logger.info(`${transactionId} has released the mutex`)
7986
}
87+
} else {
88+
logger.info(`${transactionId} did not release the mutex`)
8089
}
8190
}
8291
}
@@ -186,7 +195,11 @@ function checkEsMutexRelease (tId) {
186195
delete mutexReleaseMap[tId]
187196
transactionId = undefined
188197
if (release) {
198+
logger.info(`${tId} is releasing the mutex`)
189199
release()
200+
logger.info(`${tId} has released the mutex`)
201+
} else {
202+
logger.info(`${tId} has no mutex to release`)
190203
}
191204
}
192205
}

0 commit comments

Comments
 (0)