Skip to content

fix: avoid the non-thread-safe strerror in lean_decode_io_error#14423

Merged
TwoFX merged 3 commits into
leanprover:masterfrom
eric-wieser:patch-79
Jul 20, 2026
Merged

fix: avoid the non-thread-safe strerror in lean_decode_io_error#14423
TwoFX merged 3 commits into
leanprover:masterfrom
eric-wieser:patch-79

Conversation

@eric-wieser

@eric-wieser eric-wieser commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This PR prevents possible corruption if two threads simultaneously call lean_decode_io_error. It also changes the semantics of osCode in IO.Error, such that it emulates posix errno rather than forwarding uv error codes cast to unsigned integers.

Recall that strerror is not thread-safe.

This also removes the need to maintain two separate error lookups.

Zulip: #lean4 > Signedness of IO.Error's osCode and libuv @ 💬

This PR prevents possible corruption if two threads simultaneously call `lean_decode_io_error`.
@eric-wieser

Copy link
Copy Markdown
Contributor Author

changelog-compiler

@github-actions github-actions Bot added changelog-compiler Compiler, runtime, and FFI toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN labels Jul 16, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 16, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 94b4a6ed555fa45986f655587c1f140d11ff394a --onto a4b639c5a1e545677b36b09a4770b7b559df805b. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-16 20:42:59)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 94b4a6ed555fa45986f655587c1f140d11ff394a --onto 79bec6d064d8672cb10864cad3d9fd054b6917ae. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-17 16:21:32)

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 94b4a6ed555fa45986f655587c1f140d11ff394a --onto a4b639c5a1e545677b36b09a4770b7b559df805b. You can force reference manual CI using the force-manual-ci label. (2026-07-16 20:43:00)

@TwoFX
TwoFX added this pull request to the merge queue Jul 20, 2026
Merged via the queue into leanprover:master with commit 33ae929 Jul 20, 2026
23 checks passed
JJYYY-JJY pushed a commit to JJYYY-JJY/lean4 that referenced this pull request Jul 20, 2026
…de_io_error` (leanprover#14423)" (leanprover#14463)

This PR reverts leanprover#14423 until we can get the situation on Windows figured
out.
JJYYY-JJY pushed a commit to JJYYY-JJY/lean4 that referenced this pull request Jul 22, 2026
…eanprover#14479)

This PR prevents possible corruption if two threads simultaneously call
`lean_decode_io_error`. It also changes the semantics of `osCode` in
`IO.Error`, such that it emulates posix `errno` rather than forwarding
uv error codes cast to unsigned integers.

Recall that `strerror` is not thread-safe.

This also removes the need to maintain two separate error lookups, but
we do need to introduce a function that translates C runtime `errno`
numbers to LibUV error codes. The function `uv_translate_sys_error`
cannot be used since on Windows that one expects Windows system error
codes, which are not the same thing. This is still a win because the
translation function is much simpler than the error lookup.

This PR is a second attempt at leanprover#14423.

Zulip: [#lean4 > Signedness of IO.Error's osCode and libuv @
💬](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Signedness.20of.20IO.2EError.27s.20osCode.20and.20libuv/near/611212153)

Co-authored-by: Eric Wieser <efw@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants