'Error: Socket Hang Up with Postman API testing
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
Solution 1:[1]
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:
- 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.
- In Postman -> Settings -> General, ensure the "Timeout" value is high enough or "0" for forever.
- 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.
- Postman -> Settings -> General, try to disable "Send Postman Token"
- 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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | factorypolaris |
| Solution 2 | VivekDev |
