-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Request Executor Event Memory Leak (#6106)
- Loading branch information
1 parent
9f9bc75
commit 8a1b877
Showing
11 changed files
with
344 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/HotChocolate/Core/src/Execution/RequestExecutorEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
|
||
namespace HotChocolate.Execution; | ||
|
||
/// <summary> | ||
/// Represents the event arguments of a request executor evicted event. | ||
/// </summary> | ||
public sealed class RequestExecutorEvent : EventArgs | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="RequestExecutorEvent" />. | ||
/// </summary> | ||
/// <param name="type"> | ||
/// The type of the event. | ||
/// </param> | ||
/// <param name="name"> | ||
/// The name of the request executor that is being evicted. | ||
/// </param> | ||
/// <param name="executor"> | ||
/// The request executor that is being evicted. | ||
/// </param> | ||
internal RequestExecutorEvent( | ||
RequestExecutorEventType type, | ||
string name, | ||
IRequestExecutor executor) | ||
{ | ||
Type = type; | ||
Name = name; | ||
Executor = executor; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the type of the event. | ||
/// </summary> | ||
public RequestExecutorEventType Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the request executor that is being evicted. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the request executor that is being evicted. | ||
/// </summary> | ||
public IRequestExecutor Executor { get; } | ||
} |
59 changes: 59 additions & 0 deletions
59
src/HotChocolate/Core/src/Execution/RequestExecutorEventObserver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
|
||
namespace HotChocolate.Execution; | ||
|
||
/// <summary> | ||
/// Represents an observer that can be used to subscribe to the request executor events. | ||
/// </summary> | ||
public sealed class RequestExecutorEventObserver : IObserver<RequestExecutorEvent> | ||
{ | ||
private readonly Action<RequestExecutorEvent>? _onNext; | ||
private readonly Action<Exception>? _onError; | ||
private readonly Action? _onCompleted; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="RequestExecutorEventObserver" />. | ||
/// </summary> | ||
/// <param name="onNext"> | ||
/// The action that is invoked when a new event is received. | ||
/// </param> | ||
/// <param name="onError"> | ||
/// The action that is invoked when an error occurs. | ||
/// </param> | ||
/// <param name="onCompleted"> | ||
/// The action that is invoked when the observer is completed. | ||
/// </param> | ||
public RequestExecutorEventObserver( | ||
Action<RequestExecutorEvent>? onNext = null, | ||
Action<Exception>? onError = null, | ||
Action? onCompleted = null) | ||
{ | ||
_onNext = onNext; | ||
_onError = onError; | ||
_onCompleted = onCompleted; | ||
} | ||
|
||
/// <summary> | ||
/// Invoked when a new event is received. | ||
/// </summary> | ||
/// <param name="value"> | ||
/// The event that was received. | ||
/// </param> | ||
public void OnNext(RequestExecutorEvent value) | ||
=> _onNext?.Invoke(value); | ||
|
||
/// <summary> | ||
/// Invoked when an error occurs. | ||
/// </summary> | ||
/// <param name="error"> | ||
/// The error that occurred. | ||
/// </param> | ||
public void OnError(Exception error) | ||
=> _onError?.Invoke(error); | ||
|
||
/// <summary> | ||
/// Invoked when the observer is completed. | ||
/// </summary> | ||
public void OnCompleted() | ||
=> _onCompleted?.Invoke(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/HotChocolate/Core/src/Execution/RequestExecutorEventType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace HotChocolate.Execution; | ||
|
||
/// <summary> | ||
/// Defines the possible event types of a request executor. | ||
/// </summary> | ||
public enum RequestExecutorEventType | ||
{ | ||
/// <summary> | ||
/// A request executor was created. | ||
/// </summary> | ||
Created, | ||
|
||
/// <summary> | ||
/// A request executor was evicted. | ||
/// </summary> | ||
Evicted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.