Skip to content

Conversation

@tanner0101
Copy link
Member

@tanner0101 tanner0101 commented Nov 7, 2019

Fixes a promise leak caused by chaining the request completion promise to the channel write.

@tanner0101 tanner0101 added the bug Something isn't working label Nov 7, 2019
request.log(to: self.logger)
let promise = self.channel.eventLoop.makePromise(of: Void.self)
let request = PostgresRequestContext(delegate: request, promise: promise)
self.channel.write(request).cascadeFailure(to: promise)
Copy link
Contributor

@weissi weissi Nov 7, 2019

Choose a reason for hiding this comment

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

hmm, I don't think this can fix a promise leak, right? If anything this will make it more likely that the promise is never fulfilled. Also, this is missing a test I think?

sorry, misunderstood you. I thought you meant you leaked the unfulfilled promise but I think you mean that the old code causes a memory leak involving the promise. I still don't think this change would make that go away. The reference to promise should be dropped as soon as the self.channel.write(request) future is either fulfilled or failed.

I really don't think this can fix a memory leak. It might however cause promise to be deallocated quicker as the new code doesn't keep it around until self.channel.write(request) future is done.

}
}

extension Double: PostgresDataConvertible {
Copy link
Contributor

Choose a reason for hiding this comment

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

this and the change below seem unrelated?

@tomerd
Copy link

tomerd commented Nov 7, 2019

thanks @tanner0101

@tanner0101 tanner0101 merged commit 3f3b361 into master Nov 18, 2019
@tanner0101 tanner0101 deleted the tn-promise-leak branch November 18, 2019 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants