question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible problem with redirect logic

See original GitHub issue

If my cluster is configured to have the following members: localhost:1000, localhost:1001, localhost:1002

The following code will not redirect to the leader properly since the port that is used for the redirect is not the leader port:

internal Task Redirect(HttpContext context)
{
    if (context.Request.Path.StartsWithSegments(pathMatch, StringComparison.OrdinalIgnoreCase))
    {
        var leader = cluster.Leader;
        if (leader is null)
        {
            context.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
            return Task.CompletedTask;
        }
        else if (leader.IsRemote)
        {
            return redirection(context.Response, new UriBuilder(context.Request.GetEncodedUrl()) { Host = leader.Endpoint.Address.ToString(), Port = applicationPortHint ?? context.Connection.LocalPort }.Uri);
        }
    }

    return next(context);
}

should this not use something like the following?

new UriBuilder(context.Request.GetEncodedUrl()) { Host = leader.Endpoint.Address.ToString(), Port = leader.Endpoint.Port }.Uri)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
saknocommented, Jan 6, 2021

From my point view, your dev and test environment should be close to the production environment to eliminate potential infrastructure problems during deployment.

0reactions
saknocommented, Jan 6, 2021

I checked it on Windows, you can register additional Loopback Adapters through Control Pane as described here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirect logic in Page Object
Welcome! Next 10 minutes I'll show you the examples of redirection logic with Page Object pattern and what problem I'm trying to solve...
Read more >
How to Fix The ERR_TOO_MANY_REDIRECTS Error
ERR_TOO_MANY_REDIRECTS is, as the error suggests, caused by too many redirects, resulting in a redirect loop. Read our post to learn more.
Read more >
Advice for Logic in Javascript? - redirect
I am trying to write a redirect script for my website using Javascript and i am having some trouble with the logic. if...
Read more >
redirects in React Router v6
Redirects usually happen when you want to preserve an old link and send all the traffic bound for that destination to some new...
Read more >
HTTP trigger does not handle redirects on external calling ...
When I try this HTTP trigger from Logic App, it stops after the first redirect. However, when I try the same trigger from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found