<p>My system: Ubuntu using microk8s kubectl</p>
<p>I'm taking an online course and have run into an issue I can't find a solution to. I can't  access the following URL internally in my application</p>
<p><a href="http://ingress-nginx-controller.ingress-nginx.svc.cluster.local" rel="nofollow noreferrer">http://ingress-nginx-controller.ingress-nginx.svc.cluster.local</a></p>
<p>I get the following error in my web browser</p>
<pre><code>&quot;page&quot;: &quot;/&quot;,
&quot;query&quot;: {},
&quot;buildId&quot;: &quot;development&quot;,
&quot;isFallback&quot;: false,
&quot;err&quot;: {&quot;name&quot;: &quot;Error&quot;,&quot;message&quot;: &quot;socket hang up&quot;,&quot;stack&quot;: &quot;Error: socket hang up at connResetException (internal/errors.js:613:14) at Socket.socketOnEnd (_http_client.js:493:23) at Socket.emit (events.js:326:22) at endReadableNT (_stream_readable.js:1226:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)&quot;},
&quot;gip&quot;: true
</code></pre>
<p>and I get the following dump on node.</p>
<pre><code>[client] Error: socket hang up
[client]     at connResetException (internal/errors.js:613:14)
[client]     at Socket.socketOnEnd (_http_client.js:493:23)
[client]     at Socket.emit (events.js:326:22)
[client]     at endReadableNT (_stream_readable.js:1226:12)
[client]     at processTicksAndRejections (internal/process/task_queues.js:80:21) {
[client]   code: 'ECONNRESET',
[client]   config: {
[client]     url: 'http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser',
[client]     method: 'get',
[client]     headers: {
[client]       Accept: 'application/json, text/plain, */*',
[client]       Host: 'tickets.dev',
[client]       'User-Agent': 'axios/0.19.2'
[client]     },
[client]     transformRequest: [ [Function: transformRequest] ],
[client]     transformResponse: [ [Function: transformResponse] ],
[client]     timeout: 0,
[client]     adapter: [Function: httpAdapter],
[client]     xsrfCookieName: 'XSRF-TOKEN',
[client]     xsrfHeaderName: 'X-XSRF-TOKEN',
[client]     maxContentLength: -1,
[client]     validateStatus: [Function: validateStatus],
[client]     data: undefined
[client]   },
[client]   request: &lt;ref *1&gt; Writable {
[client]     _writableState: WritableState {
[client]       objectMode: false,
[client]       highWaterMark: 16384,
[client]       finalCalled: false,
[client]       needDrain: false,
[client]       ending: false,
[client]       ended: false,
[client]       finished: false,
[client]       destroyed: false,
[client]       decodeStrings: true,
[client]       defaultEncoding: 'utf8',
[client]       length: 0,
[client]       writing: false,
[client]       corked: 0,
[client]       sync: true,
[client]       bufferProcessing: false,
[client]       onwrite: [Function: bound onwrite],
[client]       writecb: null,
[client]       writelen: 0,
[client]       afterWriteTickInfo: null,
[client]       buffered: [],
[client]       bufferedIndex: 0,
[client]       allBuffers: true,
[client]       allNoop: true,
[client]       pendingcb: 0,
[client]       prefinished: false,
[client]       errorEmitted: false,
[client]       emitClose: true,
[client]       autoDestroy: true,
[client]       errored: false,
[client]       closed: false
[client]     },
[client]     _events: [Object: null prototype] {
[client]       response: [Function: handleResponse],
[client]       error: [Function: handleRequestError]
[client]     },
[client]     _eventsCount: 2,
[client]     _maxListeners: undefined,
[client]     _options: {
[client]       protocol: 'http:',
[client]       maxRedirects: 21,
[client]       maxBodyLength: 10485760,
[client]       path: '/api/users/currentuser',
[client]       method: 'GET',
[client]       headers: [Object],
[client]       agent: undefined,
[client]       agents: [Object],
[client]       auth: undefined,
[client]       hostname: 'ingress-nginx-controller.ingress-nginx.svc.cluster.local',
[client]       port: null,
[client]       nativeProtocols: [Object],
[client]       pathname: '/api/users/currentuser'
[client]     },
[client]     _redirectCount: 0,
[client]     _redirects: [],
[client]     _requestBodyLength: 0,
[client]     _requestBodyBuffers: [],
[client]     _onNativeResponse: [Function (anonymous)],
[client]     _currentRequest: ClientRequest {
[client]       _events: [Object: null prototype],
[client]       _eventsCount: 6,
[client]       _maxListeners: undefined,
[client]       outputData: [],
[client]       outputSize: 0,
[client]       writable: true,
[client]       destroyed: false,
[client]       _last: true,
[client]       chunkedEncoding: false,
[client]       shouldKeepAlive: false,
[client]       useChunkedEncodingByDefault: false,
[client]       sendDate: false,
[client]       _removedConnection: false,
[client]       _removedContLen: false,
[client]       _removedTE: false,
[client]       _contentLength: 0,
[client]       _hasBody: true,
[client]       _trailer: '',
[client]       finished: true,
[client]       _headerSent: true,
[client]       socket: [Socket],
[client]       _header: 'GET /api/users/currentuser HTTP/1.1\r\n' +
[client]         'Accept: application/json, text/plain, */*\r\n' +
[client]         'Host: tickets.dev\r\n' +
[client]         'User-Agent: axios/0.19.2\r\n' +
[client]         'Connection: close\r\n' +
[client]         '\r\n',
[client]       _onPendingData: [Function: noopPendingOutput],
[client]       agent: [Agent],
[client]       socketPath: undefined,
[client]       method: 'GET',
[client]       maxHeaderSize: undefined,
[client]       insecureHTTPParser: undefined,
[client]       path: '/api/users/currentuser',
[client]       _ended: false,
[client]       res: null,
[client]       aborted: false,
[client]       timeoutCb: null,
[client]       upgradeOrConnect: false,
[client]       parser: null,
[client]       maxHeadersCount: null,
[client]       reusedSocket: false,
[client]       host: 'ingress-nginx-controller.ingress-nginx.svc.cluster.local',
[client]       protocol: 'http:',
[client]       _redirectable: [Circular *1],
[client]       [Symbol(kCapture)]: false,
[client]       [Symbol(kNeedDrain)]: false,
[client]       [Symbol(corked)]: 0,
[client]       [Symbol(kOutHeaders)]: [Object: null prototype]
[client]     },
[client]     _currentUrl: 'http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser',
[client]     [Symbol(kCapture)]: false
[client]   },
[client]   response: undefined,
[client]   isAxiosError: true,
[client]   toJSON: [Function (anonymous)]
[client] }
</code></pre>
<p>my ingress-nginx service</p>
<pre><code>NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.152.183.138   &lt;pending&gt;     80:32160/TCP,443:30735/TCP   32d
ingress-nginx-controller-admission   ClusterIP      10.152.183.198   &lt;none&gt;        443/TCP                      32d
</code></pre>
<p>Project source code</p>
<p><a href="https://gitlab.com/emendoza1986/ticketingapp_microservicecourse" rel="nofollow noreferrer">https://gitlab.com/emendoza1986/ticketingapp_microservicecourse</a></p>
<p>Here is the source page <a href="https://gitlab.com/emendoza1986/ticketingapp_microservicecourse/-/blob/master/client/api/build-client.js" rel="nofollow noreferrer">https://gitlab.com/emendoza1986/ticketingapp_microservicecourse/-/blob/master/client/api/build-client.js</a> that called the link <a href="http://ingress-nginx-controller.ingress-nginx.svc.cluster.local" rel="nofollow noreferrer">http://ingress-nginx-controller.ingress-nginx.svc.cluster.local</a>, as a temporary* patch, I'm routing directly to the service I needed http://auth-srv:3000 to continue the course.</p>

<p><code>Error socket hang up</code>  error much always indicates the server closed the connection for various reason (not being able to process the request in time, or running into some error while processing the request, etc).</p>
<p>Check if  the library you are using isn’t sending requests asynchronously as  <code>pm.sendRequest()</code>  does.</p>
<p>Try to set the <code>Connection: keep-alive</code> header.
On the server side disable  <code>keepAliveTimeout</code>  by setting it equal to  <code>0</code>.
Another solution is to close free sockets in less than  <code>keepAliveTimeout</code>  value (by default it 5 seconds). The default http agent does not support such a capability (<code>timeout</code>  setting does not do it). So use  <a href="https://github.com/node-modules/agentkeepalive#readme" rel="nofollow noreferrer">agentkeepalive</a>  lib</p>
<pre><code>const HttpsAgent = require('agentkeepalive').HttpsAgent;

const agent = new HttpsAgent({
    freeSocketTimeout: 5000
});
</code></pre>
<p>More info: <a href="https://github.com/request/request/issues/2047" rel="nofollow noreferrer">connection-hang-up</a>.</p>
<p>Also if you used <strong><code>require('http')</code></strong> to consume <strong>https</strong> service and it showed &quot;<strong><code>socket hang up</code></strong>&quot;.</p>
<p>Try to change <strong><code>require('http')</code></strong> to <strong><code>require('https')</code></strong> instead, and it is working.</p>
<p>See more: <a href="https://stackoverflow.com/questions/16995184/nodejs-what-does-socket-hang-up-actually-mean">socket-hang-up</a>.
Useful blog: <a href="https://medium.com/@ehzevin/hang-in-there-a-solution-to-socket-hang-up-5e04c600fa89" rel="nofollow noreferrer">solutions-to-socket-hang-up</a>.</p>
<p>Overal it's not common to use ingress service internally within the cluster. Ingress resource is designed to manage external access to internal services.</p>
<blockquote>
<p>Note this is also a security concern as you are exposing the auth service (which is a backend service used by your UI layer) externally.</p>
</blockquote>
<p>Your network load balancer has pending <code>External IP</code>.</p>
<p>MicroK8s comes with metallb, you can enable it like this:</p>
<pre><code>microk8s enable metallb
</code></pre>
<p> should turn into an actual IP address then.</p>
<p>Take a look: <a href="https://stackoverflow.com/questions/63142877/kubernetes-ingress-nginx-routing-error-cannot-connect-frontend-to-backend">kubernetes-ingress-nginx-routing-error</a>, <a href="http://nginx.org/en/docs/http/request_processing.html" rel="nofollow noreferrer">http-request_processing</a>.</p>
