4

We have deployed some APIs (few developed using Node.js/Express.js and others using Python Quart). All out our APIs are deployed using the Azure containerized instance. We have set-up periodic API monitoring through Postman. The APIs fail about 20% of the time with Error: Socket Hang Up. We never encountered this issue in development region or when accessing the APIs via browsers. What could cause this Socket Hang Up issue and how do we overcome it?

Our Node.js APIs Dockerfiles are set-up as below:

FROM node:16

WORKDIR /app

COPY package*.json ./
RUN npm install
COPY . .
RUN rm -rf .env
RUN mv production.env .env

#ENV PORT=5000
EXPOSE 5000

CMD ["npm", "run", "prod"]

The Python Quart APIs Dockerfiles are set-up as below:

FROM continuumio/miniconda3

COPY . /api/

WORKDIR /api/src

RUN conda env create -f /api/environment.yml
COPY entrypoint.sh ./
RUN chmod +x ./entrypoint.sh

ENTRYPOINT ["./entrypoint.sh"]

EXPOSE 5000

entrypoint.sh

#!/bin/bash --login
set +euo pipefail
conda activate python_env_name
set -euo pipefail

exec hypercorn --bind 0.0.0.0:5000 QuartAPI:app
Navaneeth
  • 190
  • 1
  • 1
  • 16
  • fail for both node and python api? at the same time? How did you monitor? By accessing the api/healthcheck path? or socket call? – Someone Special Feb 13 '22 at 13:59

2 Answers2

4

Seems like more of an issue in Postman than within your API. Assuming the server is not throwing/logging any errors, it's likely the response is not being handled by Postman correctly. Here are some things in Postman that may be causing this issue:

  1. In the request: Add the header the "Content-length". It should automatically calculate the value (but you can try specifying it). If you have a value specified, ensure it's correct.
  2. In Postman -> Settings -> General, ensure the "Timeout" value is high enough or "0" for forever.
  3. Postman does not like VPN's in my experience. If you are connected to a VPN when the issue is happening, please disconnect it and try it again. If this fixes it, you'll need to create a special route out around your VPN.
  4. Postman -> Settings -> General, try to disable "Send Postman Token"
  5. Last thing to try: Postman many not be handling TLS renegotiations initiated by the server, which in multiple versions of Postman lead to connection/socket error. The issue seemed to affect Postman versions around 7.1 - 7.5. You could try updating Postman to the latest version which may be the fix.
factorypolaris
  • 2,757
  • 12
  • 15
3

For me I was missing (s) in http. So the url I was using was

http://localhost:5001/odata/People

And when I changed that to https

https://localhost:5001/odata/People

things started to work again.

VivekDev
  • 20,868
  • 27
  • 132
  • 202