flock: a contended LOCK_NB request aborts the process instead of failing with EWOULDBLOCK #1763

Closed
opened 2026-10-08 18:41:51 +00:00 by Zurisen · 0 comments
Zurisen commented 2026-10-08 18:41:51 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-08T18:41:51Z.


On main (4ddbf049), flock_nid_postfix throws on any failure of the host call (Stdio.cpp). With LOCK_NB, a lock held through another descriptor is an expected outcome: FreeBSD flock(2) returns -1 with EWOULDBLOCK (35), and the caller decides whether to retry. Here the process ends. Both platforms, not specific to one title.

Platform Host result for a contended LOCK_NB Guest sees
Linux flock -1, EWOULDBLOCK std::runtime_error, process aborts
Windows LockFileEx fails, ERROR_LOCK_VIOLATION (33) std::runtime_error, process aborts

Measured on Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0, with an exclusive lock on one descriptor and flock(other, LOCK_EX | LOCK_NB) on a second descriptor of the same file:

terminate called after throwing an instance of 'std::runtime_error'
  what():  flock_nid_postfix: flock failed, fd=4, error=33

Fixed in #1764.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5767104687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1763). Originally posted by [Zurisen](https://github.com/Zurisen) on 2026-10-08T18:41:51Z. --- On main (`4ddbf049`), `flock_nid_postfix` throws on any failure of the host call ([Stdio.cpp](https://github.com/boykopovar/AnyPS5/blob/4ddbf049/core/libs/prx/libkernel/File/src/Stdio.cpp#L271-L280)). With `LOCK_NB`, a lock held through another descriptor is an expected outcome: FreeBSD `flock(2)` returns -1 with `EWOULDBLOCK` (35), and the caller decides whether to retry. Here the process ends. Both platforms, not specific to one title. | Platform | Host result for a contended `LOCK_NB` | Guest sees | |---|---|---| | Linux | `flock` -1, `EWOULDBLOCK` | `std::runtime_error`, process aborts | | Windows | `LockFileEx` fails, `ERROR_LOCK_VIOLATION` (33) | `std::runtime_error`, process aborts | Measured on Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0, with an exclusive lock on one descriptor and `flock(other, LOCK_EX | LOCK_NB)` on a second descriptor of the same file: ``` terminate called after throwing an instance of 'std::runtime_error' what(): flock_nid_postfix: flock failed, fd=4, error=33 ``` Fixed in #1764.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#1763
No description provided.