Skip to content
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

Error: ENOENT: no such file or directory, rename '~/.ssb/gossip.json~' -> '~/.ssb/gossip.json' #597

Closed
christianbundy opened this issue Dec 19, 2018 · 4 comments
Assignees
Labels

Comments

@christianbundy
Copy link
Contributor

I was using Patchbay this morning and noticed that Electron and my browser froze at the same time while using [email protected]. I think I tried to close Electron after a few seconds, but it may have crashed, and I found these logs:

> [email protected] start /home/christianbundy/src/ssbc/patchbay
> electron index.js -- --title patchbay

STARTING electron
STARTING SBOT
LOADING config
Listening on undefined:8008 (multiserver net plugin)
listening on socket unix:/home/christianbundy/.ssb/socket
ssb-friends: stream legacy api used
Trace: deprecated api used: ssb-ref.parseAddress
    at Object.parseAddress (/home/christianbundy/src/ssbc/patchbay/node_modules/ssb-ref/index.js:96:15)
    at Socket.<anonymous> (/home/christianbundy/src/ssbc/patchbay/node_modules/scuttlebot/plugins/local.js:55:22)
    at Socket.emit (events.js:182:13)
    at Socket.<anonymous> (/home/christianbundy/src/ssbc/patchbay/node_modules/broadcast-stream/index.js:51:12)
    at Socket.emit (events.js:182:13)
    at UDP.onMessage [as onmessage] (dgram.js:673:8)
{ [Error: ENOENT: no such file or directory, rename '/home/christianbundy/.ssb/gossip.json~' -> '/home/christianbundy/.ssb/gossip.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/christianbundy/.ssb/gossip.json~',
  dest: '/home/christianbundy/.ssb/gossip.json' }
{ [Error: ENOENT: no such file or directory, rename '/home/christianbundy/.ssb/gossip.json~' -> '/home/christianbundy/.ssb/gossip.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/christianbundy/.ssb/gossip.json~',
  dest: '/home/christianbundy/.ssb/gossip.json' }
{ [Error: ENOENT: no such file or directory, rename '/home/christianbundy/.ssb/gossip.json~' -> '/home/christianbundy/.ssb/gossip.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/christianbundy/.ssb/gossip.json~',
  dest: '/home/christianbundy/.ssb/gossip.json' }
{ [Error: ENOENT: no such file or directory, rename '/home/christianbundy/.ssb/gossip.json~' -> '/home/christianbundy/.ssb/gossip.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/christianbundy/.ssb/gossip.json~',
  dest: '/home/christianbundy/.ssb/gossip.json' }

I checked my gossip.json file and I think there may have been some changes made: a few of them near the top of the file have the { duration, stateChange, client, ping, failure } keys, but most of them now look like this:

{
  "host": "diefreien.club",
  "port": 8008,
  "key": "@Y2fxCQla30qvtLJufJ57Im0on1QO72H5KECXio5xQZs=.ed25519",
  "address": "net:diefreien.club:8008~shs:Y2fxCQla30qvtLJufJ57Im0on1QO72H5KECXio5xQZs=",
  "source": "pub",
  "announcers": 523,
  "duration": null
}

After a quick git grep '~' I can't seem to figure out why a rename was happening, any chance someone else knows?

@christianbundy christianbundy self-assigned this Dec 19, 2018
@christianbundy
Copy link
Contributor Author

/shrug

@dominictarr
Copy link
Contributor

why there is a rename: writing to a temp file and renaming it to the target file gives you an atomic write https://en.wikipedia.org/wiki/Atomicity_(database_systems)

When writing a file, if the file is more than blocks it's possible that there is a failure causing the file to not be completely written. If you wrote straight to the target file, this would mean your original file is now invalid. If you write to a temp file, you can check it's all fully there and correct, then renaming it over the original file is a single operation that cannot fail part way through (it can only fully fail or fully succeed).

@christianbundy
Copy link
Contributor Author

Oh, that makes perfect sense, thanks! I guess this was probably coming from atomic-file, which explains why I couldn't find any relevant code doing file renames in the SSBC org. Thanks again, I was convinced I'd never find an answer for this.

@dominictarr
Copy link
Contributor

I learnt about that technique in this blogpost, I think: https://www.davidpashley.com/articles/writing-robust-shell-scripts/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants