# Event handle leak in mailsync.exe on Windows

**URL:** <https://community.getmailspring.com/t/event-handle-leak-in-mailsync-exe-on-windows/1022>\
**Category:** Bug Reports\
**Tags:** stability, mailsync\
**Created:** [March 8, 2021, 2:48pm UTC](https://community.getmailspring.com/t/event-handle-leak-in-mailsync-exe-on-windows/1022 "2021-03-08T14:48:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ForNeVeR](https://community.getmailspring.com/user_avatar/community.getmailspring.com/fornever/32/1135_2.png) [@ForNeVeR](https://community.getmailspring.com/u/ForNeVeR)\
**Post date:** [March 8, 2021, 2:48pm UTC](https://community.getmailspring.com/t/event-handle-leak-in-mailsync-exe-on-windows/1022/1 "2021-03-08T14:48:00Z")

</div>

## Description

I use Mailspring for six email accounts, and have noticed that `mailsync.exe` creates a lot of handles (the handle counter I have enabled in Process Hacker keeps going up; sometimes I reckon about 100k handles for all the mailsync processes in total). These handles will go away on restarting MailSpring (which, in turn, restarts all the `mailsync.exe` processes).

I have attached to a couple of processes via windbg and found that they use 15k and 25k event handles, respectively. Not sure if this is during normal operation or not, but I believe that the event handles are leaking.

## To Reproduce…

Steps to reproduce the behavior:

1. Have `mailsync.exe` running for several days
2. Attach to a `mailsync.exe` instance via windbg
3. Enter a command `!handle`
4. Note the event handle count

In one case, I had the following metrics:

```auto
Type Count
None 10
Event 26910
Section 1
File 28
Directory 4
Mutant 3
WindowStation 2
Semaphore 31
Key 17
Thread 18
Desktop 1
IoCompletion 7
TpWorkerFactory	5
ALPC Port 4
WaitCompletionPacket	14

```

## Expected Behavior

`mainsync.exe` shouldn’t leak resources even if running for several days.

## Setup

- OS and Version: Windows 10 2004
- Installation Method: via Windows installer
- Mailspring Version: 1.8.0-8983dca2

## Additional Context

I’ve found a GitHub issue mentioning a similar leak, marked as fixed in 2017: [Mailsync leaks handles · Issue #388 · Foundry376/Mailspring · GitHub](https://github.com/Foundry376/Mailspring/issues/388)

Though I still observe the leaks (have to restart Mailspring every several days to reset the handle counter).
