Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-3199] Cancel handler is never called on DispatchSource after invoking .cancel() #710

Open
swift-ci opened this issue Nov 13, 2016 · 5 comments

Comments

@swift-ci
Copy link

Previous ID SR-3199
Radar None
Original Reporter tylercloutier (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation, libdispatch
Labels Bug
Assignee mww (JIRA)
Priority Medium

md5: 1641e42bfc66b37d5426aff6370cf49c

Issue Description:

It appears that the cancel handler is never invoked after calling cancel on a DispatchSource in Swift 3 on macOS.

This issue can be replicated by following steps with Swift 3.0.1.

  1. Clone https://github.com/SwiftOnEdge/Edge.git
  2. Check out the commit 1bc2552c3f7cb0d33080d65b1290008ac5342cdf
  3. Comment out line 125 of /Sources/TCP/Server.swift and insert print statement there.
  4. Insert a print statement in the cancelHandler on line 47 of the same file
  5. Run the test RouterTests.testMiddleware

You should see that although the cancel in invoked, the test completes without ever invoking the cancel handler configured on line 47.

Shouldn't the listeningSource maintain a strong reference to the handler and submit it to the main queue (in this case) to be run when cancel is invoked or am I misunderstanding something about the contract of cancel?

Note: This is on macOS. I have not tested this for Linux.

@swift-ci
Copy link
Author

Comment by Pierre Habouzit (JIRA)

This definitely works in C, which would make it a swift issue?

@swift-ci
Copy link
Author

Comment by Tyler Cloutier (JIRA)

I would also assume it's a Swift issue. Maybe something to do with object lifetimes.

@swift-ci
Copy link
Author

Comment by Tyler Cloutier (JIRA)

As a note, I am only ever using the main queue for all dispatch tasks.

@swift-ci
Copy link
Author

Comment by Pierre Habouzit (JIRA)

are you calling dispatch_main() ? if not, you need to run the main runloop else sources won't be drained.

@swift-ci
Copy link
Author

Comment by Tyler Cloutier (JIRA)

I'm unable to call dispatch_main directly inside an XCTest. I am, however, calling waitForExpectations which should have the same effect. waitForExpectations certainly works fine to schedule my other blocks to run on the main queue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant