-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.platform:unixtopic:stdlib:filestopic:stdlib:networking
Description
UNIX targets reuse closed file descriptors which can lead to race conditions when a thread closes a fd while another thread is trying to read or write to the fd.
For example:
- Thread 1:
file = File.open("1.txt")=> ok (fd=10) - Thread 1:
file.read=> checksfile.closed?=> false => ok - Thread 1: is preempted by the OS
- Thread 2:
file.close=>LibC.close(10)=> ok - Thread X:
File.open("2.txt")=> OS reuses fd => ok (fd=10) 💣 - Thread 1: is woken by the OS
- Thread 1:
LibC.read(10)=> reads from2.txt💥
It might not be easy to trigger, and this should be a very rare scenario since a File or Socket should most often not be shared across fibers. But as always with threads: if it can happen it will happen, and when it does it will be pretty bad (data corruption, secure data leak, ...).
Metadata
Metadata
Assignees
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.platform:unixtopic:stdlib:filestopic:stdlib:networking
Type
Projects
Status
In Progress