# signalEvent not be closed

**URL:** https://discuss.elastic.co/t/signalevent-not-be-closed/157966
**Category:** Beats
**Tags:** winlogbeat
**Created:** [November 23, 2018, 7:25am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966 "2018-11-23T07:25:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![wenhaochen](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@wenhaochen](https://discuss.elastic.co/u/wenhaochen)
#### Post date: [November 23, 2018, 7:25am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/1 "2018-11-23T07:25:59Z")

</div>

Hi，

1. code from [https://github.com/elastic/beats/blob/master/winlogbeat/eventlog/wineventlog.go#L125](https://github.com/elastic/beats/blob/master/winlogbeat/eventlog/wineventlog.go#L125)  
signalEvent not be closed, handle leak might happen when calling `Open()`func many times ?

2. and one more thing confuse me:  
Pull Subscriptions example as below( [https://docs.microsoft.com/zh-cn/windows/desktop/WES/subscribing-to-events](https://docs.microsoft.com/zh-cn/windows/desktop/WES/subscribing-to-events))

```auto
 <... more ...>
 aWaitHandles[1] = CreateEvent(NULL, TRUE, TRUE, NULL);
 <... more ...>

    // Subscribe to events.
    hSubscription = EvtSubscribe(NULL, aWaitHandles[1], pwsPath, pwsQuery, NULL, NULL, NULL, EvtSubscribeStartAtOldestRecord);

// Loop until the user presses a key or there is an error.
while (true)
{
    dwWait = WaitForMultipleObjects(sizeof(aWaitHandles)/sizeof(HANDLE), aWaitHandles, FALSE, INFINITE);

    if (0 == dwWait - WAIT_OBJECT_0) // Console input
    {
        if (IsKeyEvent(aWaitHandles[0]))
            break;
    }
    else if (1 == dwWait - WAIT_OBJECT_0) // Query results
    {
        if (ERROR_NO_MORE_ITEMS != (status = EnumerateResults(hSubscription)))
        {
            break;
        }

        ResetEvent(aWaitHandles[1]);
    }
<... more ... >
}

```

compared to winlogbeat codes

> <https://github.com/elastic/beats/blob/master/winlogbeat/eventlog/wineventlog.go#L125~L140>

  
seems we do not use signalEvent as `aWaitHandles[1])` do

thanks

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 25, 2018, 10:56pm UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/2 "2018-11-25T22:56:03Z")

</div>

I think `Open()` is only called once for each event log so we haven’t observed any leaks. But it does look like the `Close()` method should be updated to all close the handle returned by `CreateEvent`.

---

<div class="post-metadata">

### Author: ![wenhaochen](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@wenhaochen](https://discuss.elastic.co/u/wenhaochen)
#### Post date: [November 28, 2018, 2:44am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/3 "2018-11-28T02:44:33Z")

</div>

In my case, if error happens, I'll call `Open()`to recreate new eventlog instance , then handle leaks observed when some error in my env;

It does hard to lead to leaks if called once, but still might cause issue sometime  
do u think should I post any fix code?

thanks

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 28, 2018, 4:07am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/4 "2018-11-28T04:07:24Z")

</div>

We might as well fix it, so yes, please.

---

<div class="post-metadata">

### Author: ![wenhaochen](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@wenhaochen](https://discuss.elastic.co/u/wenhaochen)
#### Post date: [November 30, 2018, 3:01am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/5 "2018-11-30T03:01:13Z")

</div>

one more:

> <https://github.com/elastic/beats/blob/master/winlogbeat/eventlog/wineventlog.go#L126~L128>

  
why return nil when err happens  
thanks

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 28, 2018, 3:01am UTC](https://discuss.elastic.co/t/signalevent-not-be-closed/157966/6 "2018-12-28T03:01:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
