nodejs / nodejs/node

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

Đang mở
#28,656 7 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

fs
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

  • 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng việc tái hiện với fs.access(MOUNT_PATH, fs.constants.W_OK) trên NFS mount được báo cáo, so sánh với fs.writeFileSync, fs.readFileSync, fs.stat và kiểm tra R_OK. Xác định xem kết quả khác biệt là hành vi NFS được mong đợi hay là vấn đề trong cách Node.js xử lý fs.access; hoàn thành khi đã ghi lại nguyên nhân hoặc xác định được một thay đổi runtime có trọng tâm và cách xác thực thay đổi đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.