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

fs: fix realpath{Sync} on resolving pipes/sockets #13028

Closed
wants to merge 1 commit into from

Conversation

ebraminio
Copy link
Contributor

@ebraminio ebraminio commented May 14, 2017

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

Currently

echo "" | node -e "require('fs').realpath('/dev/stdin', console.log)"

and

echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"

are broken due to our logic of realpath and this patch changes node in a way to match python:

echo "" | python -c "import os; print(os.path.realpath('/dev/stdin'))"

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label May 14, 2017
'use strict';

// Skip Windows as /dev/stdin is not available
if (process.platform === 'win32')
Copy link
Contributor

@mscdex mscdex May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use common.isWindows and common.skip() here instead. See here for an example.

});`,
`console.log(require('fs').realpathSync('/dev/stdin'));`
]) {
const child = spawn(process.execPath, ['-e', code], { stdio: 'pipe' });
Copy link
Contributor

@mscdex mscdex May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using spawnSync() instead to simplify this a bit and to make future debugging a bit easier.

@ebraminio
Copy link
Contributor Author

Both done.

@mscdex
Copy link
Contributor

mscdex commented May 15, 2017

@ebraminio
Copy link
Contributor Author

This probably needs more study, both of just not following (this patch) and following to the end and raising [current] or not raising error on following symlinks to pipes/sockets should be discussed, lets close it for now.

@ebraminio
Copy link
Contributor Author

ebraminio commented May 20, 2017

Updated to follow python result.

@ebraminio ebraminio force-pushed the unnamedpiperealpath branch 2 times, most recently from c630b2b to f39045a Compare May 20, 2017 16:50
@ebraminio
Copy link
Contributor Author

ebraminio commented May 20, 2017

@refack: Hi. Thanks for reviewing my patches. :) Does this need a documentation change also?

@ebraminio
Copy link
Contributor Author

Have a look at #13130 (comment) also

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need documentation.

process.exit(1);
};`
]) {
assert.strictEqual(spawnSync(process.execPath, ['-e', code], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In adition to sanity, I would consider asserting the value of resolvedPath and the returned value from require('fs').realpathSync('/dev/stdin');
Either in the script literal or console.loging it and adding another assert for stdout.

Copy link
Contributor Author

@ebraminio ebraminio May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that resolves to different things on different runs and platforms, that is hard to check I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than check it has a truthy value if (!resolvedPath) process.exit(2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@refack refack self-assigned this May 20, 2017
@refack
Copy link
Contributor

refack commented May 20, 2017

@ebraminio Yes, I would add a note to fs.md#fsrealpathpath-options-callback and realPathSync since this is a deviation from realpath(3).

Something like

*Note*: If `path` resolves to a Socket or a Pipe, the function will return the value of `require('path').resolve(path)`.

P.S. this might be a breaking change (a.k.a semver-major), so I've run CITGM and we'll need to compare
Baseline: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/806/testReport/
With patch: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/802/testReport/
With patch after rebase: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/805/testReport/
With patch after rebase #2: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/808/

@refack
Copy link
Contributor

refack commented May 20, 2017

since this is a deviation from realpath(3).

Or is it converted by the notes?

@ebraminio ebraminio force-pushed the unnamedpiperealpath branch 3 times, most recently from e65f679 to 035b935 Compare May 20, 2017 20:43
@ebraminio
Copy link
Contributor Author

doc is done now, have a look

doc/api/fs.md Outdated
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/13028
description: Pipe/Socket resolve support was added.
- version: REPLACEME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase on master this comment was reverted.

doc/api/fs.md Outdated
@@ -1872,10 +1879,16 @@ object with an `encoding` property specifying the character encoding to use for
the path passed to the callback. If the `encoding` is set to `'buffer'`,
the path returned will be passed as a `Buffer` object.

*Note*: If `path` resolves to a Socket or a Pipe, the function will return the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW is my note actually correct? In that case it's easy to check in the test.

Copy link
Contributor Author

@ebraminio ebraminio May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I've copy-pasted your comment just in rush, removed the both as I couldn't reach to anything useful for here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show me some input -> output results. I'll phrase something better.

Copy link
Contributor Author

@ebraminio ebraminio May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what it should be called, before my patch echo "" | node -e "require('fs').realpath('/dev/stdin', console.log)" was raising error but with my patch now it has a similar result with python, say /proc/12938/fd/pipe:[224961], just on Linux

Copy link
Contributor

@refack refack May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*Note*: If `path` resolves to a socket or a pipe, the function will return a system dependent name for that object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ebraminio ebraminio force-pushed the unnamedpiperealpath branch 2 times, most recently from e8ed5ba to eef07fc Compare May 20, 2017 21:56
@refack
Copy link
Contributor

refack commented May 20, 2017

@refack
Copy link
Contributor

refack commented May 21, 2017

So there are a linting error:

not ok 26 - /usr/home/iojs/build/workspace/node-test-linter/test/parallel/test-fs-realpath-pipe.js
message: '''expected'' is assigned a value but never used.'
  severity: error
  data:
    line: 12
    column: 7
    ruleId: no-unused-vars

and a fail on AIX:

assert.js:92
  throw new AssertionError({
  ^

AssertionError [ERR_ASSERTION]: 1 === 2
    at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-aix/nodes/aix61-ppc64/test/parallel/test-fs-realpath-pipe.js:33:10)

If you don't have a clear idea why this fails on AIX, and since this is not a regression, we could add it to /known_issues/

@ebraminio
Copy link
Contributor Author

ebraminio commented May 21, 2017

Done. I don't have access to AIX but perhaps it doesn't have the concept of /dev/stdin or that somehow is different there.

@richardlau
Copy link
Member

cc @nodejs/platform-aix

@ebraminio ebraminio mentioned this pull request May 22, 2017
4 tasks
@mhdawson
Copy link
Member

AIX does not have /dev/stdin. See the second comment in https://unix.stackexchange.com/questions/338667/unix-systems-without-dev-stdin-dev-stdout-and-dev-stderr. I also logged into the community AIX machines and there is no /dev/stdin:

# ls /dev/stdin
ls: 0653-341 The file /dev/stdin does not exist.

So although for redirection behaviour seems to be similar, the files do not actually exist in /dev.

Given that the test depends on /dev/stdin, I'd suggest it just be skipped as it is for windows.

@refack
Copy link
Contributor

refack commented May 23, 2017

AIX does not have /dev/stdin.

@mhdawson Thanks!

Given that the test depends on /dev/stdin, I'd suggest it just be skipped as it is for windows.

I'm +1

@ebraminio
Copy link
Contributor Author

Given that the test depends on /dev/stdin, I'd suggest it just be skipped as it is for windows.

Done.

@refack
Copy link
Contributor

refack commented May 25, 2017

@refack
Copy link
Contributor

refack commented May 25, 2017

arm-fanned fail is infrastructure. Landing.

refack pushed a commit to refack/node that referenced this pull request May 25, 2017
PR-URL: nodejs#13028
Reviewed-By: Refael Ackermann <refack@gmail.com>
@refack
Copy link
Contributor

refack commented May 25, 2017

Landed in b3d1e3d

@refack refack closed this May 25, 2017
jasnell pushed a commit that referenced this pull request May 28, 2017
PR-URL: #13028
Reviewed-By: Refael Ackermann <refack@gmail.com>
@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins
Copy link
Contributor

The docs here claim that it is adding a new api... should this have been semver minor?
Backport to v6.x?

@MylesBorins
Copy link
Contributor

ping

@MylesBorins
Copy link
Contributor

ping @refack

@refack
Copy link
Contributor

refack commented Sep 19, 2017

AFAICT this is semver-patch. It fixes a case that would throw

$ echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"

Error: ENOENT: no such file or directory, lstat '/proc/180/fd/pipe:[140]'
    at Object.fs.lstatSync (fs.js:961:11)
    at Object.realpathSync (fs.js:1629:21)

so now it returns a sane value:

$ echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"
/proc/577/fd/pipe:[565]

Documentation comment could have been "Pipe/Socket resolve support was added fixed."

@MylesBorins
Copy link
Contributor

@refack this doesn't appear broken on v6.x right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants