3

Disclaimer:

It's a cliche but it works on my machine(!)

Context:

Http Triggered Azure Function App Running on Windows With a "Free Tier" option.

Details:

I have an Azure Function App that host and runs a JAR file that spins up a Grizzly server which basically serves a JAVA app hosted in localhost:8080 The function app manages to start up the JAVA app by simply using. The JAVA app is called Open Trip Planner and it runs in a Grizzly server.

 Process.Start(javaPath, "<<JAR OPTIONS HERE>>");
  • Up until here it works in both my machine and Azure.

Then I run a separate thread that checks the App has started:

                  while (true)
                  {
                      Thread.Sleep(10000);
                      try
                      {
                          var result = await client.GetAsync("http://localhost:8080"); 
// <-- The above fails in Azure but not in my local machine.
                      }
                      catch (Exception ex)
                      {
                          log.LogError(ex.Message);
                      }
                  }

The exception is: "“An attempt was made to access a socket in a way forbidden by its access permissions”

Azure Function App Logs

Exception Details:

Exception Type:

System.Net.Http.HttpRequestException

Message

An attempt was made to access a socket in a way forbidden by its access permissions

StackTrace

at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at ScoreAddressFunction.ScoreAddress.<>c__DisplayClass3_0.<b__0>d.MoveNext() in /home/vsts/work/1/s/ScoreAddressFunction/ScoreAddressFunction/ScoreAddress.cs:line 85

However, it works if I change the URL to something like "https://www.google.com" which makes me think this is not caused by a limited number of available sockets as a read in other answers.

Question:

Is there something wrong -conceptually- with trying to access localhost (or 127.0.0.1) from inside an Azure Function App? Am I missing some technical / security restriction?

One of my concerns is that I am facing this issue from a wrong conceptual point of view. However, the process I run needs A LOT of memory and having it working on an Azure Function App for the time I need it would be awesome otherwise it will be very expensive.

Ricky Youssef
  • 208
  • 4
  • 8
  • 1
    Stack trace please. – user207421 Jun 13 '19 at 04:46
  • 1
    My best guess is that you were blocked by some sort of security policy configured in the JVM in the server side. Read this and research about it and Azure Function App: https://docs.oracle.com/cd/E19118-01/n1.sprovsys41/817-4820/6mkaodgb5/index.html – Jorge Campos Jun 13 '19 at 05:16

0 Answers0