fix: refcounting and error reporting in the libuv bindings - #14796
Open
algebraic-dev wants to merge 1 commit into
Open
fix: refcounting and error reporting in the libuv bindings#14796algebraic-dev wants to merge 1 commit into
algebraic-dev wants to merge 1 commit into
Conversation
Collaborator
|
Reference manual CI status:
|
algebraic-dev
added a commit
that referenced
this pull request
Aug 15, 2026
Stacks this branch on #14796 -> #14795 -> #14793. The `timer_stop`/`signal_stop` conflicts keep this branch's shape: the loop only holds a reference on a handle while it owes a promise, so the release of the promise and of the handle are gated together on the state check that #14793 introduced. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
TwoFX
approved these changes
Aug 17, 2026
Member
|
Here are two Codex-generated regression tests for a subset of the issues fixed in this PR if you want to include them: module
import Std.Internal.UV.Signal
/-!
Tests that a signal handler can retry after libuv rejects starting it.
-/
open Std.Internal.UV
def startFails (signal : @& Signal) : IO Bool := do
try
discard signal.next
return false
catch _ =>
return true
def test : IO (Bool × Bool) := do
let signal ← Signal.mk 0 false
let first ← startFails signal
let second ← startFails signal
signal.cancel
return (first, second)
/-- info: (true, true) -/
#guard_msgs in
#eval testmodule
import Std.Async.Basic
import Std.Internal.UV.TCP
/-!
Tests the error reported when a TCP shutdown is requested while one is already pending.
-/
open Std Async Net Internal.UV
def blockPromise (promise : IO.Promise (Except IO.Error α)) : IO α :=
AsyncTask.ofPromise promise |>.block
partial def recvBytes (socket : TCP.Socket) (remaining : Nat) : IO Unit := do
if remaining == 0 then
return
let some chunk ← blockPromise (← socket.recv? remaining.toUInt64)
| throw <| IO.userError "unexpected end of stream"
recvBytes socket (remaining - chunk.size)
def test : IO String := do
let server ← TCP.Socket.new
server.bind <| SocketAddressV4.mk (.ofParts 127 0 0 1) 0
server.listen 1
let addr ← server.getSockName
let acceptPromise ← server.accept
let client ← TCP.Socket.new
let connectPromise ← client.connect addr
blockPromise connectPromise
let accepted ← blockPromise acceptPromise
let size := 8 * 1024 * 1024
let payload := ByteArray.mk <| Array.replicate size 0
let sendPromise ← client.send #[payload]
let shutdownPromise ← client.shutdown
let message ← try
discard client.shutdown
pure "no error"
catch
| .otherError _ message => pure message
| error => pure s!"unexpected error: {error}"
recvBytes accepted size
blockPromise sendPromise
blockPromise shutdownPromise
return message
/-- info: "shutdown already in progress" -/
#guard_msgs in
#eval test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes reference count, mark_mt and error messages in libuv modules.