Skip to content

Commit f50ab74

Browse files
Check _cleanupTimer is not null when disposing (#4834) (#4840)
This commit checks that _cleanupTimer is not null when disposing, which it may be if no requests have been made. Fixes #4818 Co-authored-by: Russ Cam <russ.cam@elastic.co>
1 parent 1b9193d commit f50ab74

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Elasticsearch.Net/Connection/HandlerTracking/RequestDataHttpClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected virtual void StopCleanupTimer()
154154
{
155155
lock (_cleanupTimerLock)
156156
{
157-
_cleanupTimer.Dispose();
157+
_cleanupTimer?.Dispose();
158158
_cleanupTimer = null;
159159
}
160160
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
7+
using FluentAssertions;
8+
using Nest;
9+
10+
namespace Tests.Reproduce
11+
{
12+
public class GitHubIssue4818
13+
{
14+
[U]
15+
public void ConnectionSettingsDoesNotThrowNullReferenceException()
16+
{
17+
IDisposable settings = new ConnectionSettings();
18+
Action func = () => settings.Dispose();
19+
func.Should().NotThrow<NullReferenceException>();
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)