Skip to content

[SourceKit] Jump to a background queue before executing SKDUIDFromUIdent #66441

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

Merged
merged 1 commit into from
Jun 8, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jun 7, 2023

requestIsEnableBarriers and requestIsBarrier call SKDUIDFromUIdent. What I didn’t know, was that SKDUIDFromUIdent can send XPC requests to the client to translate UIDs via sourcekitd_set_uid_handlers.

Since we were calling requestIsEnableBarriers directly from the XPC server’s main queue, and the UID handler sends an XPC request synchronously, we could get into a deadlock situation.

Immediately jump onto a serial background queue (msgHandlingQueue) in sourcekitdServer_peer_event_handler so that the main queue is free to execute the UID handler. This more closely matches the behavior before I introduced barriers as well, where we were always immediately jumping onto a concurrrent msgHandlingQueue.


I think the best way to review this it to look at the combined diff of #66013 and this PR 208eaac...ahoppen:swift:ahoppen/deadlock#diff-0ef1fa70c987d3bee8fd247f1fe85ca4f3ae5ba089da80000753a9cb503ab269

@ahoppen ahoppen requested review from bnbarham and rintaro as code owners June 7, 2023 23:28
@ahoppen
Copy link
Member Author

ahoppen commented Jun 7, 2023

@swift-ci Please test

auto attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT,
auto msgHandlingQueueAttr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL,
QOS_CLASS_DEFAULT, 0);
msgHandlingQueue = dispatch_queue_create("request-handling", msgHandlingQueueAttr);
Copy link
Contributor

Choose a reason for hiding this comment

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

"message-handling"?

…dent`

`requestIsEnableBarriers` and `requestIsBarrier` call `SKDUIDFromUIdent`. What I didn’t know, was that `SKDUIDFromUIdent` can send XPC requests to the client to translate UIDs via `sourcekitd_set_uid_handlers`.

Since we were calling `requestIsEnableBarriers` directly from the XPC server’s main queue, and the UID handler sends an XPC request synchronously, we could get into a deadlock situation.

Immediately jump onto a serial background queue (`msgHandlingQueue`) in `sourcekitdServer_peer_event_handler` so that the main queue is free to execute the UID handler. This more closely matches the behavior before I introduced barriers as well, where we were always immediately jumping onto a concurrrent `msgHandlingQueue`.
@ahoppen ahoppen force-pushed the ahoppen/deadlock branch from 0a3ddd3 to f0ad258 Compare June 7, 2023 23:33
@ahoppen
Copy link
Member Author

ahoppen commented Jun 7, 2023

@swift-ci Please smoke test

@ahoppen ahoppen merged commit 23e2f34 into swiftlang:main Jun 8, 2023
@ahoppen ahoppen deleted the ahoppen/deadlock branch June 8, 2023 15:56
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