Skip to content

Commit 8ba46b5

Browse files
authored
hotfix (#134)
fixing a rare bug that would cause the service to stop working, produce a log entry "enumeration changed" 1 hour after manually removing an ip from the temporary ban list
1 parent 8954e84 commit 8ba46b5

10 files changed

Lines changed: 55 additions & 47 deletions

File tree

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## NEWS
22

3+
### 2024-05-23 release of v.2.1.62 was completed
4+
- that heisenbug that caused "enumeration changed" errors was fixed
5+
- turns out, the bug was difficult to reproduce because it happens exactly one hour after manually removing ips from the temporary ban list
6+
- thanks for reporting the stacktrace
7+
38
### 2024-05-05 release of v.2.1.61 was completed
49
- adds better support for location errors (stacktrace)
510
- displays version number correctly

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It's basically a fail2ban for windows. Its goals are also mainly what we love ab
55
- *no-initial-fucking-around-with-scripts-or-config-files*
66
- *install-and-forget*
77

8-
You can download it [here](https://github.com/devnulli/EvlWatcher/raw/master/Versions/v2/EvlWatcher-v2.1.610-setup.exe) ( v2.1.61 - May 2024 ) .
8+
You can download it [here](https://github.com/devnulli/EvlWatcher/raw/master/Versions/v2/EvlWatcher-v2.1.62-setup.exe) ( v2.1.62 - May 2024 ) .
99

1010
## Also, we love issues!
1111

Source/EvlWatcher/EvlWatcher/EvlWatcher.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public class EvlWatcher : ServiceBase, IEvlWatcherService
4848
private static readonly List<LogTask> _logTasks = new List<LogTask>();
4949
private static readonly Dictionary<LogTask, DateTime> _logTasksPerfWarningIssued = new Dictionary<LogTask, DateTime>();
5050

51-
/// <summary>
52-
/// adds some extra output
53-
/// </summary>
5451

5552
private static List<IPAddress> _lastPolledTempBans = new List<IPAddress>();
5653
private static List<IPAddress> _lastBannedIPs = new List<IPAddress>();

Source/EvlWatcher/EvlWatcher/NSIS/make.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name "EvlWatcher"
22

33
; The file to write
44
Icon EvlWatcher.ico
5-
OutFile "EvlWatcher-v2.1.61-setup.exe"
5+
OutFile "EvlWatcher-v2.1.62-setup.exe"
66

77
; The default installation directory
88
InstallDir $PROGRAMFILES\EvlWatcher

Source/EvlWatcher/EvlWatcher/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("2.1.6.1")]
32-
[assembly: AssemblyFileVersion("2.1.6.1")]
31+
[assembly: AssemblyVersion("2.1.6.2")]
32+
[assembly: AssemblyFileVersion("2.1.6.2")]

Source/EvlWatcher/EvlWatcher/tasks/GenericIPBlockingTask.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal static GenericIPBlockingTask FromConfiguration(IPersistentTaskConfigura
4646

4747
#region internal .ctor
4848

49-
internal GenericIPBlockingTask(ILogger logger)
49+
internal GenericIPBlockingTask(ILogger logger)
5050
{
5151
_logger = logger;
5252
}
@@ -85,9 +85,9 @@ public override List<IPAddress> GetTempBanVictims()
8585
}
8686

8787
//also remove forgotten IPs when its been a while
88-
List<IPAddress> removeFromForgottenList = _forgetIPsToDate.Where(p => DateTime.Now.AddHours(-1) > p.Value).Select(p=>p.Key).ToList();
88+
List<IPAddress> removeFromForgottenList = _forgetIPsToDate.Where(p => DateTime.Now.AddHours(-1) > p.Value).Select(p => p.Key).ToList();
8989
foreach (var ip in removeFromForgottenList)
90-
removeFromForgottenList.Remove(ip);
90+
_forgetIPsToDate.Remove(ip);
9191

9292
foreach (IPAddress ipToRemove in ipsToRemove)
9393
_blockedIPsToDate.Remove(ipToRemove);
@@ -118,55 +118,56 @@ public override List<IPAddress> GetPermaBanVictims()
118118

119119
protected override void OnComputeEvents(List<ExtractedEventRecord> events)
120120
{
121-
Dictionary<IPAddress, int> sourceToCount = new Dictionary<IPAddress, int>();
122-
foreach (ExtractedEventRecord e in events)
121+
lock (_syncObject)
123122
{
124-
_logger.Dump($"{Name}: Processing Event with timestamp {e.TimeCreated}", SeverityLevel.Debug);
125123

126-
string xml = e.Xml;
124+
Dictionary<IPAddress, int> sourceToCount = new Dictionary<IPAddress, int>();
125+
foreach (ExtractedEventRecord e in events)
126+
{
127+
_logger.Dump($"{Name}: Processing Event with timestamp {e.TimeCreated}", SeverityLevel.Debug);
128+
129+
string xml = e.Xml;
127130

128-
_logger.Dump($"Checking XML {xml} against boosters..", SeverityLevel.Debug);
131+
_logger.Dump($"Checking XML {xml} against boosters..", SeverityLevel.Debug);
129132

130-
bool abort = false;
131-
foreach (string b in Boosters)
132-
{
133-
_logger.Dump($"Booster: {b}", SeverityLevel.Debug);
134-
if (!xml.Contains(b))
133+
bool abort = false;
134+
foreach (string b in Boosters)
135135
{
136-
_logger.Dump($"Booster not in XML, aborting.", SeverityLevel.Debug);
137-
abort = true;
138-
break;
136+
_logger.Dump($"Booster: {b}", SeverityLevel.Debug);
137+
if (!xml.Contains(b))
138+
{
139+
_logger.Dump($"Booster not in XML, aborting.", SeverityLevel.Debug);
140+
abort = true;
141+
break;
142+
}
139143
}
140-
}
141-
if (abort)
142-
continue;
144+
if (abort)
145+
continue;
143146

144147

145-
_logger.Dump($"Checking XML against Regex {Regex} now..", SeverityLevel.Debug);
146-
Match m = Regex.Match(xml);
148+
_logger.Dump($"Checking XML against Regex {Regex} now..", SeverityLevel.Debug);
149+
Match m = Regex.Match(xml);
147150

148-
if(m.Success)
149-
{
150-
if (m.Groups.Count == 2 && IPAddress.TryParse(m.Groups[1].Value, out IPAddress ipAddress))
151+
if (m.Success)
151152
{
152-
if (_forgetIPsToDate.ContainsKey(ipAddress) && _forgetIPsToDate[ipAddress] > e.TimeCreated )
153+
if (m.Groups.Count == 2 && IPAddress.TryParse(m.Groups[1].Value, out IPAddress ipAddress))
153154
{
154-
_logger.Dump($"{Name}: found {ipAddress} but ignored it (was recently removed from autoban list)", SeverityLevel.Info);
155-
continue;
155+
if (_forgetIPsToDate.ContainsKey(ipAddress) && _forgetIPsToDate[ipAddress] > e.TimeCreated)
156+
{
157+
_logger.Dump($"{Name}: found {ipAddress} but ignored it (was recently removed from autoban list)", SeverityLevel.Info);
158+
continue;
159+
}
160+
161+
if (!sourceToCount.ContainsKey(ipAddress))
162+
sourceToCount.Add(ipAddress, 1);
163+
else
164+
sourceToCount[ipAddress]++;
165+
166+
_logger.Dump($"{Name}: found {ipAddress}, trigger count is {sourceToCount[ipAddress]}", SeverityLevel.Verbose);
156167
}
157-
158-
if (!sourceToCount.ContainsKey(ipAddress))
159-
sourceToCount.Add(ipAddress, 1);
160-
else
161-
sourceToCount[ipAddress]++;
162-
163-
_logger.Dump($"{Name}: found {ipAddress}, trigger count is {sourceToCount[ipAddress]}", SeverityLevel.Verbose);
164168
}
165169
}
166-
}
167170

168-
lock (_syncObject)
169-
{
170171
foreach (KeyValuePair<IPAddress, int> kvp in sourceToCount)
171172
{
172173
if (kvp.Value >= TriggerCount && !_blockedIPsToDate.ContainsKey(kvp.Key))

Source/EvlWatcherConsole/EvlWatcherConsole/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
5050
// übernehmen, indem Sie "*" eingeben:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("2.1.6.1")]
53-
[assembly: AssemblyFileVersion("2.1.6.1")]
52+
[assembly: AssemblyVersion("2.1.6.2")]
53+
[assembly: AssemblyFileVersion("2.1.6.2")]

Source/EvlWatcherConsole/EvlWatcherConsole/View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:vm="clr-namespace:EvlWatcherConsole.ViewModel"
5-
Title="EvlWatcher v2.1.6 Console" Height="650" Width="825" MinHeight="650" MinWidth="825" Icon="pack://application:,,,/Resources/EvlWatcher.ico" WindowStyle="ThreeDBorderWindow">
5+
Title="EvlWatcher v2.1.6.2 Console" Height="650" Width="825" MinHeight="650" MinWidth="825" Icon="pack://application:,,,/Resources/EvlWatcher.ico" WindowStyle="ThreeDBorderWindow">
66
<Window.DataContext>
77
<vm:MainWindowViewModel/>
88
</Window.DataContext>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
### 2024-05-23 release of v.2.1.62 was completed
3+
- that heisenbug that caused "enumeration changed" errors was fixed
4+
- turns out, the bug was difficult to reproduce because it happens exactly one hour after manually removing ips from the temporary ban list
5+
- thanks for reporting the stacktrace
300 KB
Binary file not shown.

0 commit comments

Comments
 (0)