Reputation: 771
My system: Ubuntu using microk8s kubectl
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
http://ingress-nginx-controller.ingress-nginx.svc.cluster.local
I get the following error in my web browser
"page": "/",
"query": {},
"buildId": "development",
"isFallback": false,
"err": {"name": "Error","message": "socket hang up","stack": "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)"},
"gip": true
and I get the following dump on node.
[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: <ref *1> 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] }
my ingress-nginx service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.152.183.138 <pending> 80:32160/TCP,443:30735/TCP 32d
ingress-nginx-controller-admission ClusterIP 10.152.183.198 <none> 443/TCP 32d
Project source code
https://gitlab.com/emendoza1986/ticketingapp_microservicecourse
Here is the source page https://gitlab.com/emendoza1986/ticketingapp_microservicecourse/-/blob/master/client/api/build-client.js that called the link http://ingress-nginx-controller.ingress-nginx.svc.cluster.local, as a temporary* patch, I'm routing directly to the service I needed http://auth-srv:3000 to continue the course.
Upvotes: 1
Views: 6968
Reputation: 7031
Error socket hang up
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).
Check if the library you are using isn’t sending requests asynchronously as pm.sendRequest()
does.
Try to set the Connection: keep-alive
header.
On the server side disable keepAliveTimeout
by setting it equal to 0
.
Another solution is to close free sockets in less than keepAliveTimeout
value (by default it 5 seconds). The default http agent does not support such a capability (timeout
setting does not do it). So use agentkeepalive lib
const HttpsAgent = require('agentkeepalive').HttpsAgent;
const agent = new HttpsAgent({
freeSocketTimeout: 5000
});
More info: connection-hang-up.
Also if you used require('http')
to consume https service and it showed "socket hang up
".
Try to change require('http')
to require('https')
instead, and it is working.
See more: socket-hang-up. Useful blog: solutions-to-socket-hang-up.
Overal it's not common to use ingress service internally within the cluster. Ingress resource is designed to manage external access to internal services.
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.
Your network load balancer has pending External IP
.
MicroK8s comes with metallb, you can enable it like this:
microk8s enable metallb
should turn into an actual IP address then.
Take a look: kubernetes-ingress-nginx-routing-error, http-request_processing.
Upvotes: 1