Skip to content

Commit fba31bb

Browse files
Rollup merge of #158326 - valentynkit:io-error-too-many-open-files, r=jhpratt
Add `io::ErrorKind::TooManyOpenFiles` Adds an unstable `io::ErrorKind::TooManyOpenFiles` for the open-file-limit condition. `EMFILE` and `ENFILE` currently decode to `ErrorKind::Uncategorized`, so stable code cannot tell that an operation failed because the process or the system ran out of file descriptors without inspecting `raw_os_error()` and a platform-specific `libc`/`windows-sys` constant. Implements the accepted ACP rust-lang/libs-team#818, including its decision to collapse `EMFILE` and `ENFILE` into a single variant. Finer-grained handling stays available through `raw_os_error()`. The variant maps: - `EMFILE` / `ENFILE` on Unix and WASI - `ERROR_TOO_MANY_OPEN_FILES` / `WSAEMFILE` on Windows - `FR_TOO_MANY_OPEN_FILES` on VEXos Tracking issue: #158319 r? libs
2 parents 270f75b + 9261852 commit fba31bb

6 files changed

Lines changed: 13 additions & 1 deletion

File tree

library/core/src/io/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ pub enum ErrorKind {
238238
#[unstable(feature = "io_error_inprogress", issue = "130840")]
239239
InProgress,
240240

241+
/// The process or the whole system has reached its limit on the number of
242+
/// open files or sockets.
243+
#[unstable(feature = "io_error_too_many_open_files", issue = "158319")]
244+
TooManyOpenFiles,
245+
241246
// "Unusual" error kinds which do not correspond simply to (sets
242247
// of) OS error codes, should be added just above this comment.
243248
// `Other` and `Uncategorized` should remain at the end:
@@ -309,6 +314,7 @@ impl ErrorKind {
309314
StorageFull => "no storage space",
310315
TimedOut => "timed out",
311316
TooManyLinks => "too many links",
317+
TooManyOpenFiles => "too many open files",
312318
Uncategorized => "uncategorized error",
313319
UnexpectedEof => "unexpected end of file",
314320
Unsupported => "unsupported",
@@ -379,6 +385,7 @@ impl ErrorKind {
379385
Unsupported,
380386
OutOfMemory,
381387
InProgress,
388+
TooManyOpenFiles,
382389
Uncategorized,
383390
})
384391
}

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
#![feature(int_from_ascii)]
356356
#![feature(io_error_inprogress)]
357357
#![feature(io_error_more)]
358+
#![feature(io_error_too_many_open_files)]
358359
#![feature(io_error_uncategorized)]
359360
#![feature(io_slice_as_bytes)]
360361
#![feature(ip)]

library/std/src/sys/fs/vexos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ fn map_fresult(fresult: vex_sdk::FRESULT) -> io::Result<()> {
612612
Err(io::const_error!(io::ErrorKind::OutOfMemory, "not enough memory for the operation"))
613613
}
614614
vex_sdk::FRESULT::FR_TOO_MANY_OPEN_FILES => Err(io::const_error!(
615-
io::ErrorKind::Uncategorized,
615+
io::ErrorKind::TooManyOpenFiles,
616616
"maximum number of open files has been reached",
617617
)),
618618
vex_sdk::FRESULT::FR_INVALID_PARAMETER => {

library/std/src/sys/io/error/unix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
137137
libc::ETXTBSY => ExecutableFileBusy,
138138
libc::EXDEV => CrossesDevices,
139139
libc::EINPROGRESS => InProgress,
140+
libc::EMFILE | libc::ENFILE => TooManyOpenFiles,
140141
libc::EOPNOTSUPP => Unsupported,
141142

142143
libc::EACCES | libc::EPERM => PermissionDenied,

library/std/src/sys/io/error/wasi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
5959
libc::ETXTBSY => ExecutableFileBusy,
6060
libc::EXDEV => CrossesDevices,
6161
libc::EINPROGRESS => InProgress,
62+
libc::EMFILE | libc::ENFILE => TooManyOpenFiles,
6263
libc::EOPNOTSUPP => Unsupported,
6364
libc::EACCES | libc::EPERM => PermissionDenied,
6465
libc::EWOULDBLOCK => WouldBlock,

library/std/src/sys/io/error/windows.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
6161
c::ERROR_POSSIBLE_DEADLOCK => return Deadlock,
6262
c::ERROR_NOT_SAME_DEVICE => return CrossesDevices,
6363
c::ERROR_TOO_MANY_LINKS => return TooManyLinks,
64+
c::ERROR_TOO_MANY_OPEN_FILES => return TooManyOpenFiles,
6465
c::ERROR_FILENAME_EXCED_RANGE => return InvalidFilename,
6566
c::ERROR_CANT_RESOLVE_FILENAME => return FilesystemLoop,
6667
_ => {}
@@ -81,6 +82,7 @@ pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
8182
c::WSAENETDOWN => NetworkDown,
8283
c::WSAENETUNREACH => NetworkUnreachable,
8384
c::WSAEDQUOT => QuotaExceeded,
85+
c::WSAEMFILE => TooManyOpenFiles,
8486
// Not a perfect mapping but this error is only returned when writing to
8587
// a socket after shutting down the write-end. On Unix targets, EPIPE is
8688
// returned in those cases.

0 commit comments

Comments
 (0)