-
Notifications
You must be signed in to change notification settings - Fork 894
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
Mailsync leaks handles #388
Comments
Hey! Thanks for the detailed report, this is really interesting. Let me see if this is also happening on Mac and Linux, it's definitely odd that it'd be windows-specific. |
Quick update: I've been able to reproduce this. Inspecting the mailsync process in windbg shows that all of these leaked event handles are created here:
It looks like this particular event is broadcast to condition_variables (which mailsync uses pretty extensively) so they can evaluate whether they should wake (https://www.sourceware.org/pthreads-win32/manual/pthread_timechange_handler_np.html). It's unclear why these aren't getting cleaned up, and also unclear why |
Interesting - this page notes that virtual machine time sync can do this (https://www.greyware.com/kb/KB2015.401.asp: "Another possible cause of unexpected clock change are time sync features of virtual machines. Be sure that the VMWare Tools/Hyper-V Integration Services Time Sync features are turned off for your VMs.") Any chance you're running Mailspring on Windows inside a VM? (I'm using VMWare Fusion) |
No, but I have Hyper-V enabled. It always runs a hypervisor underneath my host system, but as far as I know no time sync features touch the host machine. |
Hey! Thanks for the quick reply. In my VM, I disabled Time Synchronization from the virtual machine settings and it didn't have any effect, but disabling Hyper-V in Windows (by typing Definitely need to find a workaround for this (since Hyper-V is enabled by default I think...) but this should narrow it down a lot! |
I just tried disabling Hyper-V according your suggestion and was still able to reproduce the bug. |
Also, your htrace stacktrace is a bit misleading. Edit: after a quick look I think the handles are created by the constructor named Edit2: not sure if this is the matching source, but could this be the culprit? The destructor does not free the mutex. |
Not sure if github sends notifications about comment edits, so let me ping: @bengotow |
Hey! Ahh good catch—that MCObject lock is definitely suspicious. Just read it over and it seems like there should be a call to |
I recompiled the app with that additional line and it 1) doesn't crash and 2) prevents the handle count from increasing indefinitely. (I also turned Hyper-V back on and confirmed that I see the 20k+ open handles without the change.) I think that's a wrap! Really glad we got to the bottom of this. We've had some reports of Mailspring causing Windows to "hang for an extended period of time" when the computer wakes from sleep, and I think it was caused by this issue (having a zillion leaked handles around when WM_TIMECHANGE is emitted). I'm gonna PR this change into Mailcore2 and we'll see if @dinhviethoa has any thoughts. |
Go ahead and send this PR! Thanks a lot! |
Hey! The fix for this has shipped in |
This issue has been mentioned on Mailspring Community. There might be relevant details there: https://community.getmailspring.com/t/event-handle-leak-in-mailsync-exe-on-windows/1022/1 |
Mailsync processes running in the background leak massive amounts of OS handles. All of the leaked handles are handles to events that were never signaled.
Basically all operations on the account (including sync) increase the handle count by amounts varying from 1 to over 100k. Simply opening a message that Mailspring needs to download creates >1k of handles.
Log file is available here
Over time this leads to millions of open handles, which causes excessive memory usage and slight reduction of performance when opening unread messages. OS functionality is degraded - after certain number of handles, the
NtQuerySystemInformation(SystemHandleInformation)
API for querying all handles open in the OS starts to fail and debugging/security/anti-cheat tools cease to work correctly.I encountered this issue with two Gmail accounts I tested.
Are there any related issues?
No
What operating system are you using?
Windows 10 x64 version 16299
What version of Mailspring are you using?
1.0.9
--
Bug?
Do you have any third-party plugins installed? If so, which ones?
No
Is the issue related to a specific email provider (Gmail, Exchange, etc.)?
Can't determine, all my accounts are on Gmail
Is the issue reproducible with a particular attachment, message, signature, etc?
Any message, any Gmail account
The text was updated successfully, but these errors were encountered: