Skip to content

Conversation

DerGuteMoritz
Copy link
Collaborator

When putting the result deferred d in an error state, deferred returned by chain would be detected as a dropped error because it's only used to attach a side-effecting callback for cancelling the timeout. The fix then is to use on-realized instead to attach a handler for both cases. As a consequence, timeouts are now also properly cancelled when the result deferred is put in an error state, freeing up resources in a more timely fashion.

This fixes one of the causes of clj-commons/aleph#766, as well as 2 of the 3 dropped errors in manifold.go-off-test.

Also, add dedicated tests for d/timeout!.

Based on #245.

@DerGuteMoritz DerGuteMoritz changed the title Fix dropped errors in d/timeout! Fix dropped errors in manifold.deferred/timeout! Sep 19, 2025
When putting the result deferred `d` in an error state, deferred returned by `chain` would be
detected as a dropped error because it's only used to attach a side-effecting callback for
cancelling the timeout. The fix then is to use `on-realized` instead to attach a handler for both
cases. As a consequence, timeouts are now also properly cancelled when the result deferred is put in
an error state, freeing up resources in a more timely fashion.

This fixes one of the causes of clj-commons/aleph#766, as well as 2 of the
3 dropped errors in `manifold.go-off-test`.

Also, add dedicated tests for `d/timeout!`.
Comment on lines +260 to +262
t (d/timeout! d 1000)]
(d/error! d ex)
(is (= ex (deref (capture-error t) 100 ::error))))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do these numbers need to be so big?

if smaller works too that'd be better for faster tests

Suggested change
t (d/timeout! d 1000)]
(d/error! d ex)
(is (= ex (deref (capture-error t) 100 ::error))))))
t (d/timeout! d 20)]
(d/error! d ex)
(is (= ex (deref (capture-error t) 10 ::error))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants