Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where consecutive self ws calls lead to bad forwarding #377

Merged
merged 1 commit into from
Feb 3, 2025
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
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();
}
}
}
}
Loading