Skip to content

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

Closed
ebraminio wants to merge 1 commit into
nodejs:masterfrom
ebraminio:unnamedpiperealpath
Closed

fs: fix realpath{Sync} on resolving pipes/sockets#13028
ebraminio wants to merge 1 commit into
nodejs:masterfrom
ebraminio:unnamedpiperealpath

Conversation

@ebraminio

@ebraminioebraminio commented May 14, 2017

Copy link
Copy Markdown
Contributor
  • 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-botnodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label May 14, 2017
@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch from 4104b3d to 84cbd7aCompareMay 14, 2017 23:22

@mscdexmscdexMay 15, 2017

Copy link
Copy Markdown
Contributor

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.

@mscdexmscdexMay 15, 2017

Copy link
Copy Markdown
Contributor

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
ebraminioforce-pushed the unnamedpiperealpath branch from 84cbd7a to 1fa2c30CompareMay 15, 2017 06:39
@ebraminio

Copy link
Copy Markdown
ContributorAuthor

Both done.

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch from 1fa2c30 to dbac492CompareMay 15, 2017 06:58
@mscdex

Copy link
Copy Markdown
Contributor

@ebraminio

Copy link
Copy Markdown
ContributorAuthor

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.

@ebraminioebraminio reopened this May 20, 2017
@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch from dbac492 to 00f1de7CompareMay 20, 2017 16:25
@ebraminio

ebraminio commented May 20, 2017

Copy link
Copy Markdown
ContributorAuthor

Updated to follow python result.

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch 2 times, most recently from c630b2b to f39045aCompareMay 20, 2017 16:50
@ebraminio

ebraminio commented May 20, 2017

Copy link
Copy Markdown
ContributorAuthor

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

@ebraminio

Copy link
Copy Markdown
ContributorAuthor

Have a look at #13130 (comment) also

@refackrefack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need documentation.

Copy link
Copy Markdown
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.

@ebraminioebraminioMay 20, 2017

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@refackrefack self-assigned this May 20, 2017
@refack

refack commented May 20, 2017

Copy link
Copy Markdown
Contributor

@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

refack commented May 20, 2017

Copy link
Copy Markdown
Contributor

since this is a deviation from realpath(3).

Or is it converted by the notes?

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch 3 times, most recently from e65f679 to 035b935CompareMay 20, 2017 20:43
@ebraminio

Copy link
Copy Markdown
ContributorAuthor

doc is done now, have a look

Comment threaddoc/api/fs.md Outdated

Copy link
Copy Markdown
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.

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch from 035b935 to f0146f4CompareMay 20, 2017 21:41
Comment threaddoc/api/fs.md Outdated

Copy link
Copy Markdown
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.

@ebraminioebraminioMay 20, 2017

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

@ebraminioebraminioMay 20, 2017

Copy link
Copy Markdown
ContributorAuthor

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

@refackrefackMay 20, 2017

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch 2 times, most recently from e8ed5ba to eef07fcCompareMay 20, 2017 21:56
@refack

Copy link
Copy Markdown
Contributor

@refack

Copy link
Copy Markdown
Contributor

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
ebraminioforce-pushed the unnamedpiperealpath branch from e1ae7c5 to 9746ad1CompareMay 21, 2017 05:39
@ebraminio

ebraminio commented May 21, 2017

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
Member

cc @nodejs/platform-aix

@ebraminioebraminio mentioned this pull request May 22, 2017
4 tasks
@mhdawson

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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
ebraminioforce-pushed the unnamedpiperealpath branch from 9746ad1 to d4d9120CompareMay 23, 2017 20:35
@ebraminio

Copy link
Copy Markdown
ContributorAuthor

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

Done.

@ebraminio
ebraminioforce-pushed the unnamedpiperealpath branch from d4d9120 to 363020cCompareMay 24, 2017 14:43
@refack

Copy link
Copy Markdown
Contributor

@refack

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

Landed in b3d1e3d

@refackrefack 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>
@jasnelljasnell mentioned this pull request May 28, 2017
@gibfahngibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins

Copy link
Copy Markdown
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
Copy Markdown
Contributor

ping

@MylesBorins

Copy link
Copy Markdown
Contributor

ping @refack

@refack

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

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

Labels

fsIssues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@ebraminio@mscdex@refack@richardlau@mhdawson@MylesBorins@nodejs-github-bot