Breaking Change 61070: Add a .close() method to ResourceHandle

94 views
Skip to first unread message

Brian Quinlan

unread,
Jul 7, 2025, 2:05:59 PMJul 7
to anno...@dartlang.org

Change Intent
Add a .close() method to ResourceHandle that frees the file descriptor that the ResourceHandle is managing.

Justification
The current design of ResourceHandle is racy because it allows a file descriptor to be sent over a Unix Domain Socket without ensuring that the file descriptor is still open. It also allows a file descriptor to be recovered into a RandomAccessFile, Socket, etc. without ensuring that the file descriptor is valid.

https://dart-review.googlesource.com/c/sdk/+/428905 fixes those lifetime issues by duplicating input file descriptors. It frees them using a finalizer but a .close() method will ensure that those file descriptors are closed promptly.

Impact
This change will break anyone who implements ResourceHandle without implementing noSuchMethod. On GitHub, no such usages exist.

Mitigation
Developers must modify all classes that implements ResourceHandle without implementing noSuchMethod.

Reply all
Reply to author
Forward
0 new messages