swiftlang / swiftlang/swift-corelibs-libdispatch

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

Open
#710 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Foundation libdispatch
Dominant language
C
Stars
2.6k
Forks
496
Avg merge
2d 6h
Merged PRs (30d)
3

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the macOS behavior using the Edge commit 1bc2552c3f7cb0d33080d65b1290008ac5342cdf, focusing on Sources/TCP/Server.swift lines 47 and 125 and RouterTests.testMiddleware. Check the DispatchSource cancellation contract and compare the observed output with the expected cancel-handler behavior; done means the issue is resolved or the platform-specific contract is clearly established by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, swift
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.