Skip to content

Commit

Permalink
fix: prevent EMFILE error in environment low file descriptors limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tamoreton committed Jan 5, 2025
1 parent 49e75b8 commit 79a53c0
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/content/read.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fs = require('fs/promises')
const fs = require('fs-extra')
const fsm = require('fs-minipass')
const ssri = require('ssri')
const contentPath = require('./path')
Expand Down
2 changes: 1 addition & 1 deletion lib/content/rm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const fs = require('fs/promises')
const fs = require('fs-extra')
const contentPath = require('./path')
const { hasContent } = require('./read')

Expand Down
2 changes: 1 addition & 1 deletion lib/content/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const events = require('events')

const contentPath = require('./path')
const fs = require('fs/promises')
const fs = require('fs-extra')
const { moveFile } = require('@npmcli/fs')
const { Minipass } = require('minipass')
const Pipeline = require('minipass-pipeline')
Expand Down
2 changes: 1 addition & 1 deletion lib/entry-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
readdir,
rm,
writeFile,
} = require('fs/promises')
} = require('fs-extra')
const { Minipass } = require('minipass')
const path = require('path')
const ssri = require('ssri')
Expand Down
2 changes: 1 addition & 1 deletion lib/rm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { rm } = require('fs/promises')
const { rm } = require('fs-extra')
const glob = require('./util/glob.js')
const index = require('./entry-index')
const memo = require('./memoization')
Expand Down
2 changes: 1 addition & 1 deletion lib/util/tmp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { withTempDir } = require('@npmcli/fs')
const fs = require('fs/promises')
const fs = require('fs-extra')
const path = require('path')

module.exports.mkdir = mktmpdir
Expand Down
2 changes: 1 addition & 1 deletion lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
stat,
truncate,
writeFile,
} = require('fs/promises')
} = require('fs-extra')
const contentPath = require('./content/path')
const fsm = require('fs-minipass')
const glob = require('./util/glob.js')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"license": "ISC",
"dependencies": {
"@npmcli/fs": "^4.0.0",
"fs-extra": "^11.2.0",
"fs-minipass": "^3.0.0",
"glob": "^10.2.2",
"lru-cache": "^10.0.1",
Expand Down
4 changes: 2 additions & 2 deletions test/content/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getReadStatFailure = (t, err) => getRead(t, {
throw err
},
},
'fs/promises': {
'fs-extra': {
...fs.promises,
stat: async () => {
throw err
Expand Down Expand Up @@ -219,7 +219,7 @@ t.test('read: returns only first result if other hashes fails', function (t) {
t.test('read: opening large files', function (t) {
const CACHE = t.testdir()
const mockedRead = getRead(t, {
'fs/promises': {
'fs-extra': {
...fs.promises,
stat: async () => {
return { size: Number.MAX_SAFE_INTEGER }
Expand Down
4 changes: 2 additions & 2 deletions test/entry-index.insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ t.test('ENOENT from appendFile is ignored', async (t) => {
const cache = t.testdir()

const indexMocked = t.mock('../lib/entry-index.js', {
'fs/promises': {
'fs-extra': {
...fs,
appendFile: async () => {
throw Object.assign(new Error('fake enoent'), { code: 'ENOENT' })
Expand All @@ -239,7 +239,7 @@ t.test('generic error from appendFile rejects', async (t) => {
const cache = t.testdir()

const indexMocked = t.mock('../lib/entry-index.js', {
'fs/promises': {
'fs-extra': {
...fs,
appendFile: async () => {
throw Object.assign(new Error('fake eperm'), { code: 'EPERM' })
Expand Down
4 changes: 2 additions & 2 deletions test/entry-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ missingFileError.code = 'ENOENT'

const getEntryIndex = (t, opts) => t.mock('../lib/entry-index', opts)
const getEntryIndexReadFileFailure = (t, err) => getEntryIndex(t, {
'fs/promises': {
'fs-extra': {
...fs.promises,
readFile: async () => {
throw err
Expand Down Expand Up @@ -233,7 +233,7 @@ t.test('lsStream: missing files error', async (t) => {
t.test('lsStream: unknown error reading dirs', (t) => {
const cache = t.testdir(cacheContent)
const { lsStream } = getEntryIndex(t, {
'fs/promises': {
'fs-extra': {
...fs.promises,
readdir: async () => {
throw genericError
Expand Down
6 changes: 3 additions & 3 deletions test/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ t.test('missing file error when validating cache content', async t => {
const missingFileError = new Error('ENOENT')
missingFileError.code = 'ENOENT'
const mockVerify = getVerify(t, {
'fs/promises': Object.assign({}, fs, {
'fs-extra': Object.assign({}, fs, {
stat: async () => {
throw missingFileError
},
Expand All @@ -238,7 +238,7 @@ t.test('missing file error when validating cache content', async t => {

t.test('unknown error when validating content', async t => {
const mockVerify = getVerify(t, {
'fs/promises': Object.assign({}, fs, {
'fs-extra': Object.assign({}, fs, {
stat: async () => {
throw genericError
},
Expand Down Expand Up @@ -274,7 +274,7 @@ t.test('unknown error when rebuilding bucket', async t => {
// shouldFail controls the right time to mock the error
let shouldFail = false
const mockVerify = getVerify(t, {
'fs/promises': Object.assign({}, fs, {
'fs-extra': Object.assign({}, fs, {
stat: async (path) => {
if (shouldFail) {
throw genericError
Expand Down

0 comments on commit 79a53c0

Please sign in to comment.