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

WaitForPort hangs forever. #92

Closed
maurovisintin opened this issue Aug 5, 2019 · 10 comments
Closed

WaitForPort hangs forever. #92

maurovisintin opened this issue Aug 5, 2019 · 10 comments
Assignees
Labels
bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.

Comments

@maurovisintin
Copy link

maurovisintin commented Aug 5, 2019

Running the following snippet:

protected override Task OnStart(CancellationToken cancellationToken)
        {
            try
            {
                this.Logger.LogInformation("Starting mailhog container. This may take a few minutes if the image is not in local cache.");

                this.containerService = new Builder()
                    .UseContainer()
                    .WithName("profiles-smtp-server")
                    .UseImage("mailhog/mailhog:latest")
                    .ReuseIfExists()
                    .ExposePort(5011, 8025)
                    .ExposePort(1025) 
                    .WaitForPort("8025/tcp", 5000)
                    .Build();

                this.containerService.Start();
            }
            catch (FluentDockerException ex) when (ex.Message.Contains("Error response from daemon: Conflict"))
            {
                this.Logger.LogInformation("Seq container already running.");
            }
            this.Logger.LogInformation("mailhog started");
            return Task.CompletedTask;
        }

I can see the log info for the container starting, but never get to the "started" message.
The process waits indefinitely for the port.

After some minutes I get:

[16:23:16 FTL] Host terminated unexpectedly
Ductus.FluentDocker.Common.FluentDockerException: Timeout waiting for service at = 31.199.53.9 port = 5011 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Operation timed out [::ffff:31.199.53.9]:5011
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at Ductus.FluentDocker.Services.Extensions.NetworkExtensions.WaitForPort(IPEndPoint endpoint, Int64 millisTimeout)
   --- End of inner exception stack trace ---

I see the container running

121509a22f7d        mailhog/mailhog:latest   "MailHog"                About a minute ago   Up About a minute      0.0.0.0:32774->1025/tcp, 0.0.0.0:5011->8025/tcp                                                                                                                                 profiles-smtp-server

and I can successfully access to mailhog ui at http://localhost:5011/

mariotoffia pushed a commit that referenced this issue Aug 6, 2019
Could not replicate Issue #92.
@mariotoffia
Copy link
Owner

@maurovisintin Do you have some sort of firewall rules or otherwise routing table that is not correct? I've wrote a unit test to simulate your setup on my local as follows

 [TestMethod]
    public void Issue92()
    {
      using (var c = Fd.UseContainer()
        .WithName("profiles-smtp-server")
        .UseImage("mailhog/mailhog:latest")
        .ReuseIfExists()
        .ExposePort(5011, 8025)
        .ExposePort(1025)
        .WaitForPort("8025/tcp", TimeSpan.FromSeconds(30))
        .Build())
      {
        c.Start();
        var response = $"http://{c.ToHostExposedEndpoint("8025/tcp")}/".Wget().Result;
        IsTrue(response.IndexOf("<title>MailHog</title>", StringComparison.Ordinal) != -1);
      }
    }

and it works fine. Can you do a curl 31.199.53:9:5011 successfully (replace IP with your current IP)?

@maurovisintin
Copy link
Author

maurovisintin commented Aug 6, 2019

Thanks for the quick response.
As I mentioned in the issue, I can successfully access to http://localhost:5011/ both from chrome and curl.
But the process never gets past c.Start();

@mariotoffia
Copy link
Owner

mariotoffia commented Aug 6, 2019

Yes, but not on your IP address since fluentdocker resolves the IP address and do not use localhost. Can you, please, try to access using the IP address from chrome instead and see if you get the same behaviour?

Cheers,
Mario

@maurovisintin
Copy link
Author

I tried with my Private IP Address, http://192.168.1.215:5011/ and still works as expected.

@mariotoffia
Copy link
Owner

mariotoffia commented Aug 6, 2019

Hmm... do your computer have both a private and public ip address? It seems that the framework choose your public in that case 31.199.53.9and I'm guessing that it is under firewall.. It this is the case, I'll need to add the checks and always strive to use private ones...

@maurovisintin
Copy link
Author

Actually 31.199.53.9 is neither my private or public IP, trying to understand why is it looking for that IP

@mariotoffia
Copy link
Owner

mariotoffia commented Aug 6, 2019

@maurovisintin It resolves your address using the container network configuration - so it is the address of the container (doing docker inspect and checks the network section of the container).

I'm adding a way to specify which address to use when doing the waitfor operation thus it is possible to do e.g.

 using (var c = Fd.UseContainer()
        .WithName("profiles-smtp-server")
        .UseImage("mailhog/mailhog:latest")
        .ReuseIfExists()
        .ExposePort(5011, 8025)
        .ExposePort(1025)
        .WaitForPort("8025/tcp", TimeSpan.FromSeconds(30), "127.0.0.1")
        .Build())
      {
        c.Start();
        var port = c.ToHostExposedEndpoint("8025/tcp").Port;
        var response = $"http://127.0.0.1:{port}/".Wget().Result;
        IsTrue(response.IndexOf("<title>MailHog</title>", StringComparison.Ordinal) != -1);
      }
    }

In this example it will use the loopback to call the container if e.g. bound to 0.0.0.0

@mariotoffia mariotoffia self-assigned this Aug 6, 2019
@mariotoffia mariotoffia added bug under-development Denotes that a issue is under development but not yet released. under-investigation A investigation is made around the issue labels Aug 6, 2019
@mariotoffia mariotoffia added this to To do in FluentDocker via automation Aug 6, 2019
mariotoffia pushed a commit that referenced this issue Aug 6, 2019
If the resolved container IP is not reachable it is possible to specify an IP address that is should use again. This relates to Issue #92. Set version to 2.7.0
@mariotoffia
Copy link
Owner

@maurovisintin Do you have the ability to clone the master and test the extension on WaitForPort to see if this solves your issue?

Cheers,
Mario

@mariotoffia
Copy link
Owner

@maurovisintin I've pushed release 2.7.0 to nuget - no need to clone. However, if you find the root cause of the problem I would really like to have that feedback and how you have setup your networking.

It may take some time before 2.7.0 is indexed/published on nuget

Cheers,
Mario

@mariotoffia mariotoffia added waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. and removed under-development Denotes that a issue is under development but not yet released. under-investigation A investigation is made around the issue labels Aug 6, 2019
@maurovisintin
Copy link
Author

It works, thanks for the support!

FluentDocker automation moved this from To do to Done Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.
Projects
FluentDocker
  
Done
Development

No branches or pull requests

2 participants