Add cancellable DTLS connection attempts - #35
Conversation
ecc963e to
e4fa70d
Compare
|
Three new lifecycle verbs land here:
So On the cancellation mechanism itself. Polling a self._wake_r, self._wake_w = socket.socketpair()
...
ready, _, _ = select.select([sock, self._wake_r], [], [], remaining)Cancel writes a byte, I know that's a design change to code you've already written, tested and stress-run 25 times, which is the most expensive kind of review comment, but I think it's for the best here. Same rebase note as #34. |
e4fa70d to
3f0e437
Compare
|
Agreed. I’ve pulled quiesce_for_close(), abort(), the in-progress-socket state, pending-request changes, and all established-session lifecycle behavior out of this PR. It now does connection-attempt cancellation only and is stacked solely on #34, with no #33 dependency. One implementation detail changed from the original version: an ordinary threading.Event has no selectable file descriptor, so combining it with select() would still require either polling or a watcher thread. I replaced it with a one-way ConnectCancellation signal backed by socketpairs for active attempts. set() writes the wake byte, select() returns immediately, and the per-attempt sockets are retired afterward. A signal arriving after the connection has been established does not alter that session. Happy to change anything else as you see fit! |
|
Merged in v0.1.7, thanks. The socketpair-backed One narrow race for a follow-up, non-blocking. The "does not alter an already established session" contract has a gap at the very end of |
Problem
A caller can bound
connect(), but it cannot stop an attempt that is no longer needed. Polling athreading.Eventadds cancellation latency and requires separate socket ownership just to interrupt a blocked receive.Changes
connect(cancel=...)using a one-wayConnectCancellationsignal.set()makes the wake socket readable immediately.select(), without a polling interval or watcher thread.SessionClosedErrorwhen cancellation wins.This revision deliberately removes
quiesce_for_close(),abort(), the in-progress-socket field, pending-request locking/wakeup changes, and all established-session lifecycle changes. Those should be introduced only with a concrete consumer that establishes their required shape.An ordinary
threading.Eventhas no selectable file descriptor, so using it withselect()would require either polling or a helper thread.ConnectCancellationexposes the same smallset()/is_set()shape while providing the socket wakeup directly.Validation
Tests cover invalid and pre-set signals, cancellation across setup phases, immediate wake from a blocked
select(), multiple subscribers, the handshake-success race, successful non-cancelled connection state, socket cleanup, and redacted local wakeup failures.Stack
Depends only on #34 at
a44930f, which is now directly on currentmainand independent of #33. The new commit for this slice is3f0e437.