-
Notifications
You must be signed in to change notification settings - Fork 737
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
Fix windows SockState reference counting + misc clean-ups #1149
Conversation
d6819d9
to
8b13d05
Compare
@dtacalau Can you check this PR for the memory leak you discovered? |
6ab4edf
to
d6e7e79
Compare
Sure, will check it! |
@piscisaureus I've checked this PR on all tests, here are the results:
|
src/sys/windows/selector.rs
Outdated
self.pending_evts = self.user_evts; | ||
forget(self_arc.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks strange, why call forget on the clone and not on the self_arc directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self_arc is a reference here. Dropping a reference does is no-op, therefore ’forget’ing a reference instead of dropping doesn't make any difference.
src/sys/windows/selector.rs
Outdated
@@ -626,7 +585,7 @@ impl SelectorInner { | |||
n += 1; | |||
continue; | |||
} | |||
let sock_arc = Arc::from_raw(iocp_event.overlapped() as *const Mutex<SockState>); | |||
let sock_arc: Pin<Arc<Mutex<SockState>>> = transmute_copy(&iocp_event.overlapped()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a perfect copy without increasing the ref count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. It's basically reinterpret_cast + copy.
0001-Added-support-to-cancel-sock-state-on-selector-drop.zip @piscisaureus here's a patch done on your branch which add support for cancel on drop. Using this patch there are no more leaks. Let me know what you think! |
…nt memory leaks for sockets which have been registered and haven't been deregistered or sockets with no events polled. Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
77872be
to
6003655
Compare
I've addressed the correctness issues I found in your patch (it's still messy nonetheless) and added a counter to check for leaked SockState (now SockStateInner) objects. Based on the counter I'd say that there are no SockStateInner objects being leaked. However DrMemory still finds leaks for me, so I'm pretty sure it's something else that's leaking. |
@piscisaureus not sure about merging b994c29. It looks like a lot of refactoring done and release date is getting close, test coverage could be better, feels risky. I'd defer this decision to @carllerche and @Thomasdezeeuw. But if we still want to merge this, I'd suggest splitting it in multiple, more trackable, smaller commits, i.e: one comit for fix windows Sock ref count, multiple misc clean-ups comits. |
@piscisaureus Have a look at #1147, I've redone my initial mem leak fix by just adding the cancel sockstate on drop on current master and all the leaks are gone. Not sure if the correctness issues you've mentioned are gone, can you take a look? We could merge this to keep things simple. |
Fair enough. WDYT about #1154? That at least gets rid of an unnecessary Box around Overlapped and that wonky self_overlapped thing. |
Is the plan to merge #1154 first? Because I think there is some overlap/conflicts with this pr. |
@piscisaureus #1154 looks good! We still need to fix the mem leak afterwards. |
@Thomasdezeeuw Here's how I see the plan: I also think #1154 should be merged first. The misc clean-ups done by @piscisaureus are definitely useful, but, to me, it seemed too many changes at once, so I suggested splitting them in multiple commits. At the same time we should come up with a fix for the memory leaks (delete remaining sock states when doing selector drop). |
#1154 is merged, what is left to do here? |
@Thomasdezeeuw there are several misc clean-ups remaining. @piscisaureus do you want to create a separate commit with remaining clean-ups so we can merge them? |
I'll do it when I have time, but I won't have time for at least a week and a half. These misc cleanups are not super important IMO, so just forget about them for now. There were a few small bug fixes contained in the patch. When I have the time I'll prioritize on landing those. |
No description provided.