Skip to content

🍒[5.9][IRGen] Distributed: Destroy loaded arguments after the call #65941

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 6 commits into from
May 22, 2023

Conversation

ktoso
Copy link
Contributor

@ktoso ktoso commented May 16, 2023

Description: Decoding of remote call arguments is synthesized in IR, and the lifetime of the arguments that have been loaded due to underlying method conversion have to be destroyed after the call otherwise they are going to leak. This PR fixes this lifetime issue resolving the memory leak of arguments passed to remote call targets.
EDIT: Added the follow up from #65952 immediately here; which fixes the order in which we destroy and dealloc: we MUST deallocate AFTER we destroy since otherwise the destroy does not make the refcount drop to zero, and we were still missing deinitializers running. The patch now contains complete fix.

Risk: Low, isolated to distributed remote calls; confirmed to work on all platforms
Review by: @jckarter
Testing: CI testing
Original PR: #65874
Radar: rdar://109207043
Resolves: #65853

@ktoso ktoso requested a review from a team as a code owner May 16, 2023 09:01
@ktoso ktoso requested review from jckarter, DougGregor and hborla May 16, 2023 09:03
@ktoso ktoso changed the title [IRGen] Distributed: Destroy loaded arguments after the call 🍒[5.9][IRGen] Distributed: Destroy loaded arguments after the call May 16, 2023
@ktoso ktoso added distributed Feature → concurrency: distributed actor 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels May 16, 2023
@ktoso
Copy link
Contributor Author

ktoso commented May 16, 2023

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented May 16, 2023

Weird failure, I'll investigate

<unknown>:0: error: error opening '/home/build-user/build/buildbot_linux/swift-linux-x86_64/test-linux-x86_64/Distributed/Output/distributed_actor_thunk_doesnt_leak_class_arguments.swift.tmp/FakeDistributedActorSystems.swiftmodule' for output: No such file or directory

and I'll destroy them in reverse order as we create

@@ -575,6 +581,13 @@ void DistributedAccessor::emitLoadOfWitnessTables(llvm::Value *witnessTables,
}

void DistributedAccessor::emitReturn(llvm::Value *errorValue) {
// Destroy loaded arguments.
// This MUST be done before deallocating, as otherwise we'd try to swift_release freed memory,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the latest change is this; we MUST destroy BEFORE we dealloc (ofc, duh, ufff)

@ktoso
Copy link
Contributor Author

ktoso commented May 19, 2023

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented May 19, 2023

Fixed formatting

@ktoso
Copy link
Contributor Author

ktoso commented May 19, 2023

@swift-ci please test

@ktoso ktoso force-pushed the pick-rdar-109207043 branch from 1593dee to 585cde3 Compare May 19, 2023 22:40
@ktoso
Copy link
Contributor Author

ktoso commented May 19, 2023

@swift-ci please test

xedin and others added 5 commits May 20, 2023 15:59
Arguments that have been loaded due to underlying method conversion
have to be destroyed after the call otherwise they are going to leak.

Resolves: swiftlang#65853
Resolves: rdar://109207043
@ktoso ktoso force-pushed the pick-rdar-109207043 branch from 585cde3 to 2f34f20 Compare May 20, 2023 14:00
@ktoso
Copy link
Contributor Author

ktoso commented May 20, 2023

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented May 22, 2023

What; I'm checking this exact same branch locally and the test passes... Looking into it hmm

@ktoso
Copy link
Contributor Author

ktoso commented May 22, 2023

Could have been the missing empty directory directive hmmm

@ktoso
Copy link
Contributor Author

ktoso commented May 22, 2023

@swift-ci please test

@ktoso
Copy link
Contributor Author

ktoso commented May 22, 2023

Interesting, that was it so I'll bring that 1803771 (#65941) over to main too

@ktoso ktoso merged commit f54dee1 into swiftlang:release/5.9 May 22, 2023
@ktoso ktoso deleted the pick-rdar-109207043 branch May 22, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants