-
-
Notifications
You must be signed in to change notification settings - Fork 478
fix: ignore stale keystore lockfiles #6363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,45 @@ | ||
| export type Lockfile = { | ||
| lockSync(path: string): void; | ||
| unlockSync(path: string): void; | ||
| }; | ||
|
|
||
| const lockFile: Lockfile = (await import("lockfile")) as Lockfile; | ||
|
|
||
| function getLockFilepath(filepath: string): string { | ||
| return `${filepath}.lock`; | ||
| } | ||
|
|
||
| /** | ||
| * When lockfile is imported, it registers listeners to process | ||
| * Since it's only used by the validator client, require lazily to not pollute | ||
| * beacon_node client context | ||
|
Comment on lines
-13
to
-15
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This statement was no longer true since the migration to ESM in #3978. It was also already noted in #3978 (comment) but having async file locking causes a bunch of upstream issues. |
||
| */ | ||
| function getLockFile(): Lockfile { | ||
| return lockFile; | ||
| } | ||
| import {lockSync, unlockSync} from "proper-lockfile"; | ||
|
|
||
| /** | ||
| * Creates a .lock file for `filepath`, argument passed must not be the lock path | ||
| * @param filepath File to lock, i.e. `keystore_0001.json` | ||
| */ | ||
| export function lockFilepath(filepath: string): void { | ||
| getLockFile().lockSync(getLockFilepath(filepath)); | ||
| try { | ||
| lockSync(filepath, { | ||
| // Allows to lock files that do not exist | ||
| realpath: false, | ||
| }); | ||
| } catch (e) { | ||
| if (isLockfileError(e) && e.code === "ELOCKED") { | ||
| e.message = `${filepath} is already in use by another process`; | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Deletes a .lock file for `filepath`, argument passed must not be the lock path | ||
| * @param filepath File to unlock, i.e. `keystore_0001.json` | ||
| */ | ||
| export function unlockFilepath(filepath: string): void { | ||
| // Does not throw if the lock file is already deleted | ||
| // https://github.com/npm/lockfile/blob/6590779867ee9bdc5dbebddc962640759892bb91/lockfile.js#L68 | ||
| getLockFile().unlockSync(getLockFilepath(filepath)); | ||
| try { | ||
| unlockSync(filepath, { | ||
| // Allows to unlock files that do not exist | ||
| realpath: false, | ||
| }); | ||
| } catch (e) { | ||
| if (isLockfileError(e) && e.code === "ENOTACQUIRED") { | ||
| // Do not throw if the lock file is already deleted | ||
| return; | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| // https://github.com/moxystudio/node-proper-lockfile/blob/9f8c303c91998e8404a911dc11c54029812bca69/lib/lockfile.js#L53 | ||
| export type LockfileError = Error & {code: "ELOCKED" | "ENOTACQUIRED"}; | ||
|
|
||
| function isLockfileError(e: unknown): e is LockfileError { | ||
| return e instanceof Error && (e as LockfileError).code !== undefined; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer required as proper-lockfile adds this extension by default, see lib/lockfile.js#L12