Skip to content

fix(RemoteAuth): correct auth zip directory based on writable of cwd#201726

Open
huynhtuandat05december wants to merge 2 commits intowwebjs:mainfrom
huynhtuandat05december:fix/remote-auth-zip-directory
Open

fix(RemoteAuth): correct auth zip directory based on writable of cwd#201726
huynhtuandat05december wants to merge 2 commits intowwebjs:mainfrom
huynhtuandat05december:fix/remote-auth-zip-directory

Conversation

@huynhtuandat05december
Copy link
Copy Markdown

Description

Fixes ENOENT failures when RemoteAuth is paired with remote stores like wwebjs-aws-s3 or wwebjs-mongo.

Since #3375, the session zip is written to this.dataPath. However, store adapters (S3, GridFS) open the zip by its relative filename (e.g. RemoteAuth-<sessionId>.zip), which Node resolves against process.cwd(). When dataPath and cwd differ, the upload step can't find the file and crashes:

node:internal/process/promises:394
  triggerUncaughtException(err, true /* fromPromise */);
[Error: ENOENT: no such file or directory, open 'RemoteAuth-XXXXXXXXXX.zip'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'RemoteAuth-XXXXXXXXXX.zip'
}
Node.js v24.15.0
ELIFECYCLE  Command failed with exit code 1.

This PR resolves a single zipDir at construction time so the zip lives where store adapters expect it, while preserving #3375 Lambda support:

  • If process.cwd() is writable => use it. The zip lands at the path store adapters resolve relative filenames against, so S3 / GridFS uploads succeed.
  • Otherwise => fall back to this.dataPath (Lambda's read-only root filesystem, only /tmp writable — Store RemoteAuth ZIP files inside dataPath #3375).

Both the archiver output path (backup => upload to S3 / Mongo) and the extract path (download => restore) use this.zipDir, so the write and read locations stay consistent.

Related Issue(s)

closes #5781

Testing Summary

Test Details

  • PNPM:
pnpm add github:huynhtuandat05december/whatsapp-web.js#fix/remote-auth-zip-directory
  • YARN:
yarn add github:huynhtuandat05december/whatsapp-web.js#fix/remote-auth-zip-directory
  • NPM:
npm install github:huynhtuandat05december/whatsapp-web.js#fix/remote-auth-zip-directory

Environment

  • Machine OS: macOS 15
  • Phone OS: iOS 26.0
  • Library Version: 1.34.6 - main branch with latest commit hash is 211205363c06b0a4d35f0047adce07da937ffc19
  • WhatsApp Web Version: 2.3000.1017054665
  • Browser Type and Version: Chromium 120
  • Node Version: 24.15.0

Type of Change

  • Dependency change (package changes such as removals, upgrades, or additions)
  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-code change (documentation, README, etc.)

Checklist

  • My code follows the style guidelines of this project.
  • All new and existing tests pass (npm test).
  • Typings (e.g. index.d.ts) have been updated if necessary.
  • Usage examples (e.g. example.js) / documentation have been updated if applicable.

@github-actions github-actions Bot added the api changes API modifications label Apr 23, 2026
@jusufalwi
Copy link
Copy Markdown

PR #201726 - fix(RemoteAuth): correct auth zip directory based on writable of cwd

Looked at the change. The approach makes sense - checking process.cwd() writability at startup and falling back to dataPath if not.

One thing to consider: the fallback is silent. If cwd becomes unwritable after initialization (or if someone is debugging why zips ended up in a different location), there's no indication it happened. Not a blocker, but a log.warn or similar would help.

Also worth noting: if dataPath is also not writable, the error will surface later during compressSession rather than at construction. The error message at that point won't be obvious. Again, not a blocker for this fix since you're improving the common case, but something to keep in mind.

The core logic looks correct. Ship it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote Auth Sessions are not restoring after server reload

2 participants