nodejs / nodejs/node

fs.access throws permission error while checking W_OK on writable dir

オープン
#28,656 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

fs
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

  • Version: v10.16.0 (also happening on v12.6.0)
  • Platform: 18.6.0 Darwin Kernel Version 18.6.0 (also happening on 4.15.0-54-generic Ubuntu)
  • Subsystem: fs

I'm experiencing a rather unexpected behaviour when trying fs.access on a directory that's also an NFS shared mount point. The check for fs.constants.W_OK throws Error: EACCES: permission denied, access '/mnt/test/nfs' even though the directory is writable and permissions seem to be correct for the user running the node script process.

Below is a reproduction of what I'm seeing.

const os = require('os');
const path = require('path');
const fs = require('fs');

// Path to the mount directory
const MOUNT_PATH = '/mnt/test/nfs';

const filePath = path.join(MOUNT_PATH, 'foo.txt');

// Write a file
fs.writeFileSync(filePath, 'Hello world!'); // Passes OK

// Read a file
const contents = fs.readFileSync(filePath); // Passes OK
console.log(contents.toString('utf-8')); // 'Hello World!'

// Get stats
os.userInfo();
/*
{
  uid: 431,
  gid: 433,
  username: 'test',
  homedir: '/home/test',
  shell: '/sbin/nologin'
}
*/

fs.stat(MOUNT_PATH, console.log);
/*
> null Stats {
  dev: 52,
  mode: 16895, <- '0777' octal
  nlink: 1,
  uid: 431, <- Correct uid
  gid: 433, <- Correct gid
  rdev: 0,
  blksize: 4096,
  ino: 263,
  size: 184,
  blocks: 0,
  atimeMs: 1562948571578.2288,
  mtimeMs: 1562897414354.1873,
  ctimeMs: 1562897414354.1873,
  birthtimeMs: 0,
  atime: 2019-07-12T16:22:51.578Z,
  mtime: 2019-07-12T02:10:14.354Z,
  ctime: 2019-07-12T02:10:14.354Z,
  birthtime: 1970-01-01T00:00:00.000Z
}
*/


// Test permissions
fs.access(MOUNT_PATH, fs.constants.R_OK, console.error); // Passes OK
fs.access(MOUNT_PATH, fs.constants.W_OK, console.error); 
/* 
 [Error: EACCES: permission denied, access '/mnt/test/nfs'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'access',
  path: '/mnt/test/nfs'
*/

This does not happen on any other directory outside the NFS share. I stumbled upon the exception when writing a very simple health checker script to test the mount availability for a running web service.

Am I missing something? What's the catch here? Thanks in advance.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

報告された NFS マウント上で fs.access(MOUNT_PATH, fs.constants.W_OK) を使用して再現することから始め、fs.writeFileSync、fs.readFileSync、fs.stat、および R_OK チェックと比較します。異なる結果が想定される NFS の動作なのか、Node.js における fs.access の処理の問題なのかを判断します。原因を文書化するか、対象を絞った runtime の変更とその検証を特定できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。