Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .build/Build.Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ partial class Build
const string Net50 = "net5.0";
const string Net60 = "net6.0";

readonly int DegreeOfParallelism = System.Environment.ProcessorCount * 3;
readonly int DegreeOfParallelism = 2;

AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath AllSolutionFile => SourceDirectory / "All.sln";
Expand Down
6 changes: 3 additions & 3 deletions .build/Build.Sonar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner;
using Serilog;
using static System.IO.Path;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;
using static Helpers;
using Serilog;

partial class Build
{
Expand Down Expand Up @@ -89,7 +89,7 @@ SonarScannerBeginSettings SonarBeginPrSettings(SonarScannerBeginSettings setting
.Add("/d:sonar.pullrequest.key={0}", GitHubPRNumber)
.Add("/d:sonar.pullrequest.branch={0}", GitHubHeadRef)
.Add("/d:sonar.pullrequest.base={0}", GitHubBaseRef)
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"))
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "false"))
.SetFramework(Net50);

SonarScannerBeginSettings SonarBeginFullSettings(SonarScannerBeginSettings settings) =>
Expand All @@ -108,7 +108,7 @@ SonarScannerBeginSettings SonarBeginBaseSettings(SonarScannerBeginSettings setti
.AddSourceExclusions("**/Generated/**/*.*,**/*.Designer.cs,**/*.generated.cs,**/*.js,**/*.html,**/*.css,**/Sample/**/*.*,**/Samples.*/**/*.*,**/*Tools.*/**/*.*,**/Program.Dev.cs, **/Program.cs,**/*.ts,**/*.tsx,**/*EventSource.cs,**/*EventSources.cs,**/*.Samples.cs,**/*Tests.*/**/*.*,**/*Test.*/**/*.*")
.SetProcessArgumentConfigurator(t => t
.Add("/o:{0}", "chillicream")
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"));
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "false"));

SonarScannerBeginSettings SonarBaseSettings(SonarScannerBeginSettings settings) =>
settings
Expand Down
30 changes: 30 additions & 0 deletions src/HotChocolate/AspNetCore/HotChocolate.AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.AspNetCore.Aut
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.AspNetCore.Authorization.Tests", "test\AspNetCore.Authorization.Tests\HotChocolate.AspNetCore.Authorization.Tests.csproj", "{CBADBC3F-FACC-424C-8E7D-28A029F5C238}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Transport.Sockets", "src\Transport.Sockets\HotChocolate.Transport.Sockets.csproj", "{8E85603A-E36A-4133-BF04-7734BCD02D1F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Transport.Sockets.Client", "src\Transport.Sockets.Client\HotChocolate.Transport.Sockets.Client.csproj", "{1284182A-3F75-4AF3-A1EE-7D7085C3545A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -249,6 +253,30 @@ Global
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x64.Build.0 = Release|Any CPU
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x86.ActiveCfg = Release|Any CPU
{CBADBC3F-FACC-424C-8E7D-28A029F5C238}.Release|x86.Build.0 = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x64.ActiveCfg = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x64.Build.0 = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x86.ActiveCfg = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Debug|x86.Build.0 = Debug|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|Any CPU.Build.0 = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x64.ActiveCfg = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x64.Build.0 = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x86.ActiveCfg = Release|Any CPU
{8E85603A-E36A-4133-BF04-7734BCD02D1F}.Release|x86.Build.0 = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x64.ActiveCfg = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x64.Build.0 = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x86.ActiveCfg = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Debug|x86.Build.0 = Debug|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|Any CPU.Build.0 = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x64.ActiveCfg = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x64.Build.0 = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x86.ActiveCfg = Release|Any CPU
{1284182A-3F75-4AF3-A1EE-7D7085C3545A}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -270,6 +298,8 @@ Global
{9957A20C-4DCC-4643-B97D-ACF00D75C702} = {8A75EB03-3E25-4819-AE7D-1159D5AED817}
{3DA60297-97CB-4712-89C6-F71EB75F98EA} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
{CBADBC3F-FACC-424C-8E7D-28A029F5C238} = {936FF2E5-6576-4257-A7A3-F2093D44E6CD}
{8E85603A-E36A-4133-BF04-7734BCD02D1F} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
{1284182A-3F75-4AF3-A1EE-7D7085C3545A} = {2E2070DF-95C2-48F2-A8DF-7FE3734817ED}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EAA92712-961A-4595-82AD-C031830477CC}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\..\..\Core\src\Core\HotChocolate.Core.csproj" />
<ProjectReference Include="..\..\..\Core\src\Types.Scalars.Upload\HotChocolate.Types.Scalars.Upload.csproj" />
<ProjectReference Include="..\Transport.Sockets\HotChocolate.Transport.Sockets.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Buffers;
using HotChocolate.AspNetCore.Subscriptions.Protocols;
using HotChocolate.Transport.Sockets;
using Microsoft.AspNetCore.Http;

namespace HotChocolate.AspNetCore.Subscriptions;
Expand All @@ -8,18 +9,13 @@ namespace HotChocolate.AspNetCore.Subscriptions;
/// The socket connection represent an accepted connection with a socket
/// where the protocol is already negotiated.
/// </summary>
public interface ISocketConnection : IHasContextData, IDisposable
public interface ISocketConnection : ISocket, IHasContextData, IDisposable
{
/// <summary>
/// Gets access to the HTTP Context.
/// </summary>
HttpContext HttpContext { get; }

/// <summary>
/// Specifies if the connection is closed.
/// </summary>
bool IsClosed { get; }

/// <summary>
/// Gets access to the request scoped service provider.
/// </summary>
Expand Down Expand Up @@ -48,19 +44,6 @@ ValueTask SendAsync(
ReadOnlyMemory<byte> message,
CancellationToken cancellationToken = default);

/// <summary>
/// Reads a message from the client.
/// </summary>
/// <param name="writer">
/// The writer to which the message is written to.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
ValueTask ReceiveAsync(
IBufferWriter<byte> writer,
CancellationToken cancellationToken = default);

/// <summary>
/// Closes the connection with the client.
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@ public PingPongJob(ISocketSession session, GraphQLSocketOptions options)
_options = options;
}

public void Begin(CancellationToken cancellationToken)
=> Task.Factory.StartNew(
() => KeepConnectionAliveAsync(cancellationToken),
cancellationToken,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);

private async Task KeepConnectionAliveAsync(CancellationToken ct)
public async Task RunAsync(CancellationToken cancellationToken)
{
ISocketConnection connection = _session.Connection;
IProtocolHandler protocolHandler = _session.Protocol;

try
{
// first we will wait for a connection to be established
await Task.Delay(_options.ConnectionInitializationTimeout, ct);
await Task.Delay(_options.ConnectionInitializationTimeout, cancellationToken);

// if after the timeout no connection initialization was send by the client we will
// close the connection.
if (!connection.ContextData.ContainsKey(ConnectionContextKeys.Connected))
{
await _session.Protocol.OnConnectionInitTimeoutAsync(_session, ct);
await _session.Protocol.OnConnectionInitTimeoutAsync(_session, cancellationToken);
return;
}

Expand All @@ -45,18 +38,18 @@ private async Task KeepConnectionAliveAsync(CancellationToken ct)
{
TimeSpan interval = _options.KeepAliveInterval.Value;

while (!connection.IsClosed && !ct.IsCancellationRequested)
while (!connection.IsClosed && !cancellationToken.IsCancellationRequested)
{
await Task.Delay(interval, ct);
await Task.Delay(interval, cancellationToken);

if (!connection.IsClosed)
{
await protocolHandler.SendKeepAliveMessageAsync(_session, ct);
await protocolHandler.SendKeepAliveMessageAsync(_session, cancellationToken);
}
}
}
}
catch (OperationCanceledException) when (ct.IsCancellationRequested)
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
// the message processing was canceled.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using HotChocolate.Utilities;
using static HotChocolate.AspNetCore.Properties.AspNetCoreResources;
using static HotChocolate.AspNetCore.Subscriptions.ConnectionContextKeys;
using static HotChocolate.AspNetCore.Subscriptions.ProtocolNames;
using static HotChocolate.Transport.Sockets.WellKnownProtocols;
using static HotChocolate.AspNetCore.Subscriptions.Protocols.MessageUtilities;
using static HotChocolate.AspNetCore.Subscriptions.Protocols.Apollo.MessageProperties;
using static HotChocolate.Language.Utf8GraphQLRequestParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ internal static class Utf8MessageBodies
{
private static readonly byte[] _keepAlive =
{
(byte)'{',
(byte)'"',
(byte)'t',
(byte)'y',
(byte)'p',
(byte)'e',
(byte)'"',
(byte)':',
(byte)'"',
(byte)'k',
(byte)'a'
(byte)'a',
(byte)'"',
(byte)'}'
};

public static ReadOnlyMemory<byte> KeepAlive => _keepAlive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using HotChocolate.Execution.Serialization;
using HotChocolate.Language;
using HotChocolate.Utilities;
using static HotChocolate.AspNetCore.Subscriptions.ProtocolNames;
using static HotChocolate.Transport.Sockets.WellKnownProtocols;
using static HotChocolate.AspNetCore.Subscriptions.Protocols.MessageUtilities;
using static HotChocolate.AspNetCore.Subscriptions.ConnectionContextKeys;
using static HotChocolate.AspNetCore.Subscriptions.Protocols.GraphQLOverWebSocket.MessageProperties;
Expand Down Expand Up @@ -190,7 +190,7 @@ idProp.ValueKind is JsonValueKind.String &&
public ValueTask SendKeepAliveMessageAsync(
ISocketSession session,
CancellationToken cancellationToken)
=> SendPongMessageAsync(session, null, cancellationToken);
=> SendPingMessageAsync(session, null, cancellationToken);

public async ValueTask SendResultMessageAsync(
ISocketSession session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@ public interface IProtocolHandler
/// </summary>
string Name { get; }

/// <summary>
/// Is invoked by the socket session for every incoming message.
/// </summary>
/// <param name="session">
/// The socket session.
/// </param>
/// <param name="message">
/// The client message.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>

ValueTask OnReceiveAsync(
ISocketSession session,
ReadOnlySequence<byte> message,
Expand Down
Loading