Skip to content

Commit 2a00021

Browse files
committed
more debugging
1 parent 72e3057 commit 2a00021

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

workspaces/libnpmexec/lib/with-lock.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
const fs = require('node:fs/promises')
23
const { rmdirSync } = require('node:fs')
34
const promiseRetry = require('promise-retry')
@@ -143,18 +144,28 @@ async function maintainLock (lockPath) {
143144
// fs.utimes operates on floating points seconds (directly, or via strings/Date objects), which may not match the underlying filesystem's mtime precision, meaning that we might read a slightly different mtime than we write. always round to the nearest second, since all filesystems support at least second precision
144145
let mtime = Math.round(stats.mtimeMs / 1000)
145146
const signal = controller.signal
147+
let touchCount = 0
146148

147149
async function touchLock () {
150+
touchCount++
148151
try {
152+
const currentTouchCount = touchCount
153+
const start = Date.now()
154+
console.log(`${currentTouchCount} fs.stat start`)
149155
const currentStats = (await fs.stat(lockPath))
156+
console.log(`${currentTouchCount} fs.stat done in ${Date.now() - start}ms`)
150157
const currentMtime = Math.round(currentStats.mtimeMs / 1000)
151158
if (currentStats.ino !== stats.ino || currentMtime !== mtime) {
159+
console.log(`${currentTouchCount} expected ${currentStats.ino} === ${stats.ino} and ${currentMtime} === ${mtime}`)
152160
throw new Error('Lock compromised')
153161
}
154162
mtime = Math.round(Date.now() / 1000)
155163
// touch the lock, unless we just released it during this iteration
156164
if (currentLocks.has(lockPath)) {
165+
const start2 = Date.now()
166+
console.log(`${currentTouchCount} fs.utimes start`)
157167
await fs.utimes(lockPath, mtime, mtime)
168+
console.log(`${currentTouchCount} fs.utimes done in ${Date.now() - start2}ms`)
158169
}
159170
} catch (err) {
160171
// stats mismatch or other fs error means the lock was compromised

0 commit comments

Comments
 (0)