Skip to content

Commit

Permalink
Fix bug where consecutive self ws call leads to bad forwarding (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
haga-rak authored Feb 3, 2025
1 parent e738b8b commit 594f6a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Fluxzy.Core/Core/ProxyOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,20 @@ public async ValueTask Operate(TcpClient client, RsBuffer buffer, bool closeImme
var endPoint = (IPEndPoint)client.Client.RemoteEndPoint!;
var localEndPoint = (IPEndPoint)client.Client.LocalEndPoint!;

exchange.Metrics.DownStreamClientPort = endPoint.Port;
exchange.Metrics.DownStreamClientAddress = endPoint.Address.ToString();
exchange.Metrics.DownStreamLocalPort = localEndPoint.Port;
exchange.Metrics.DownStreamLocalAddress = localEndPoint.Address.ToString();
exchange.Context.DownStreamLocalAddressStruct = localEndPoint.Address;
exchange.Context.ProxyListenPort = _proxyRuntimeSetting.ProxyListenPort;

var shouldClose = false;

var downStreamClientAddress = endPoint.Address.ToString();
var localEndPointsAddress = localEndPoint.Address.ToString();

do
{
exchange.Metrics.DownStreamClientPort = endPoint.Port;
exchange.Metrics.DownStreamClientAddress = downStreamClientAddress;
exchange.Metrics.DownStreamLocalPort = localEndPoint.Port;
exchange.Metrics.DownStreamLocalAddress = localEndPointsAddress;
exchange.Context.DownStreamLocalAddressStruct = localEndPoint.Address;
exchange.Context.ProxyListenPort = _proxyRuntimeSetting.ProxyListenPort;

var processMessage = !exchange.Unprocessed;

if (processMessage)
Expand Down
28 changes: 28 additions & 0 deletions test/Fluxzy.Tests/Cases/SelfCallTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2021 - Haga Rakotoharivelo - https://github.com/haga-rak

using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Fluxzy.Tests.Cases
{
public class SelfCallTests
{
[Fact]
public async Task MakeMultipleSelfCall()
{
var setting = FluxzySetting.CreateLocalRandomPort();

await using var proxy = new Proxy(setting);

var endPoints = proxy.Run();
using var client = HttpClientUtility.CreateHttpClient(endPoints, setting);

for (int i = 0; i < 4; i++) {
var response = await client.GetAsync($"http://127.0.0.1:{endPoints.First().Port}/welcome");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
}
}
}
}

0 comments on commit 594f6a6

Please sign in to comment.