Postman : socket hang up
Asked Answered
F

25

50

I just started using Postman. I had this error "Error: socket hang up" when I was executing a collection runner. I've read a few post regarding socket hang up and it mention about sending a request and there's no response from the server side and probably timeout. How do I extend the length of time of the request in Postman Collection Runner?

Flask answered 8/6, 2017 at 4:17 Comment(7)
Are single requests / tests working?Slob
nope. its not working. Im sending a file(an image with the size 20kb)Flask
Have same issue. I run postman collection 100 times (with different variables) and 1-2 requests failed with socked hang up.Niello
You can change the timeout 0 in the settings to eliminate the timeout. but Socket hang up is not a timeout error. I'm facing the same thing on a form post.Cristionna
I am getting the error as well on a post request I have been executing all day, and that still works in SOAP-UI. No clue what is causing the issue...Achromic
late to add but this can help someone . In my case, i had kept debug pointers in my IDE for debugging purpose. First,i did one POST request to localhost API and was debugging, in parallel tried to do another POST request to different endpoints. In this case, Socket hang up occured. It was due to proxy setting. Check this thread for more information - community.postman.com/t/… Note: I was using a VPNCaliginous
adding http:// | https:// (depending on which is the case) to the endpoint url solved my problem.Conni
T
46

For me it was because my application was switched to https and my postman requests still had http in them. Changing postman to https fixed it.

Toney answered 20/6, 2022 at 13:4 Comment(3)
How did you switch to https ? Do you mean in the request address bar ? Because I'm requesting GET http://localhost:49153/api/stocks/get with response Error: socket hang up.Stockwell
yes, try https on that get callToney
Just tried that, my error changed to "Error: tunneling socket could not be established, statusCode=502"Ontology
C
20

Socket hang up, error is port related error. I am sharing my experience. When you use same port for connecting database, which port is already in use for other service, then "Socket Hang up" error comes out.

eg:- port 6455 is dedicated port for some other service or connection. You cannot use same port (6455) for making a database connection on same server.

Caudal answered 7/5, 2019 at 13:20 Comment(3)
For me , the server was in https and I was calling in httpDogmatics
Thanks bro, it took me days. Changed Spring boot server.port 8088 to 8089 and all started to work!Hinds
Hi @IlkhomKhodjaev, I am glad it is working now.Caudal
W
9

Sometimes, this error rises when a client waits for a response for a very long time. This can be resolved using the 202 (Accepted) Http code. This basically means that you will tell the server to start the job you want it to do, and then, every some-time-period check if it has finished the job.

If you are the one who wrote the server, this is relatively easy to implement. If not, check the documentation of the server you're using.

Waw answered 9/5, 2020 at 14:27 Comment(2)
how can you return any code if the server hasn't yet finished its job?Joacimah
The first sentence in the attached link: "HTTP Status 202 indicates that the request has been accepted for processing, but the processing has not been completed."Waw
N
7

Postman was giving "Could not get response" "Error: socket hang up". I solved this problem by adding the Content-Length http header to my request

Newson answered 19/8, 2020 at 14:45 Comment(5)
thank you, it worked for me. I copied the request from some other source and then changed the payload data in my POST request. so, there was a mismatch in Content-Length. :)Plan
And what length should that be?Evanevander
@OliverDixon, it should be automatically calculated (default option). Also, for me the issue was in disabling Host headerEmmaemmalee
So for example, testing with postman, how do I calculate the length?Evanevander
It also works if you simply add Content-Type and I added application/vnd.api+json as the value.Gaylenegayler
G
5

I have just faced the same problem and I fixed it by close my VPN. So I guess that's a network agent problem. You can check if you have some network proxy is on.

Groundmass answered 8/9, 2020 at 2:11 Comment(1)
Thank youuuu! I still often forget that VPNs are an all-source of problems! (when one works in IT)Mischa
P
3

I defined Authenticate method to generate a token and mentioned its return type as nullable string as:

public string? Authenticate(string username, string password) 
{
  if(!users.Any(u => u.Key==username && u.Value == password))
    {
      return null;
    }
  var tokenHandler = new JwtSecurityTokenHandler();


  var tokenKey = Encoding.ASCII.GetBytes(key);
  var tokenDescriptor = new SecurityTokenDescriptor()
  {
    Subject = new ClaimsIdentity(new Claim[]
    {
       new Claim(ClaimTypes.Name, username)
    }),
    Expires = DateTime.UtcNow.AddHours(1),
    SigningCredentials = new SigningCredentials(new 
    SymmetricSecurityKey(tokenKey), 
    SecurityAlgorithms.HmacSha256Signature)
  };
   var token = tokenHandler.CreateToken(tokenDescriptor);
   return tokenHandler.WriteToken(token);
}

Changing nullable string to simply string fixed "Socket Hang Up" issue for me!

Phobe answered 4/10, 2022 at 6:14 Comment(0)
L
2

I solved this problem with disconnection my vpn. you should check if there is vpn connected.

Lacustrine answered 13/6, 2020 at 6:45 Comment(0)
C
2

For me the issue was related to the mismatch of the http versions on the client and server.

Client was assuming http v2 while server (spring boot/ tomcat) in the case was http v1

When on the server I configured server to v2, the issue got resolved in a go.

In spring boot you can configure the http v2 as below:-

server.http2.enabled=true

Note - Also the scenario was related to using client auth mechanism (i.e. MTLS)

Without client auth/ MTLS it worked without issues, but after setting correct version in spring boot - that was the important rescue point

Cockleshell answered 1/1, 2023 at 6:48 Comment(0)
S
1

What helped for me was replacing 'localhost' in the url to http://127.0.0.1 or whatever other address your local machine has assigned localhost to.

Symbol answered 23/6, 2020 at 11:27 Comment(0)
C
1

Are you using nodemon, or some other file-watcher? In my case, I was generating some local files, uploading them, then sending the URL back to my user. Unfortunately nodemon would see the "changes" to the project, and trigger a restart before a response was sent. I ignored the build directories from my file-watcher and solved this issue.

Here is the Nodemon readme on ignoring files: https://github.com/remy/nodemon#ignoring-files

Carrew answered 6/8, 2020 at 15:2 Comment(0)
L
1

this happaned when client wait for response for long time try to sync your API requests from postman

then make login post and your are done

Lutetium answered 21/10, 2020 at 6:52 Comment(0)
T
0

If Postman doesn't get response within a specified time it will throw the error "socket hang up".

I was doing something like below to achieve 60 minutes of delay between each scenario in a collection:

get https://postman-echo.com/delay/10
pre request script :-
setTimeout(function(){}, [50000]);

I reduced time duration to 30 seconds:

setTimeout(function(){}, [20000]);

After that I stopped getting this error.

Tegular answered 27/8, 2019 at 13:1 Comment(0)
A
0

It's possible there are 2 things, happening at the same time.

  1. The url contains a port which is not commonly used AND
  2. you are using a VPN or proxy that does not support that port.

I had this problem. My server port was 45860 and I was using pSiphon anti-filter VPN. In that condition my Postman reported "connection hang-up" only when server's reply was an error with status codes bigger than 0. (It was fine when some text was returning from server with no error code.)

When I changed my web service port to 8080 on my server, WOW, it worked! even though pSiphon VPN was connected.

Absorbefacient answered 24/9, 2020 at 21:55 Comment(0)
C
0

Socket hang up error could be due to the wrong URL of the API you are trying to access in the postman. please check the URL once carefully.

Cardinale answered 5/11, 2020 at 3:41 Comment(1)
Verify https URL or Http URL in variables of POSTMANGratify
D
0

Following on Abhay's answer: double check the scheme. A server that is secured may disconnect if you call an https endpoint with http.

This happened to me while debugging an ASP.NET Core API running on localhost using the local cert. Took me a while to figure out since it was inside a Postman environment and also it was a Monday.

Daryldaryle answered 11/5, 2021 at 12:25 Comment(0)
C
0

In my case, adding in the header the "Content-length" parameter did the job.

My environment is

Mac: [Terminal command: sw_vers] ProductName: macOS ProductVersion: 12.0.1. (Monterey) BuildVersion: 21A559

mysql:
[Terminal command: mysql --version] Ver 8.0.27 for macos11.6 on x86_64 (Homebrew)

Apache: [Terminal command: httpd -v] Server version: Apache/2.4.48 (Unix) Server built: Oct 1 2021 20:08:18.

*Laravel [Terminal command: php artisan --version] Laravel Framework 8.76.2

Postman Version 9.1.5 (9.1.5)

Conchaconchie answered 23/12, 2021 at 14:10 Comment(0)
C
0

socket hang up error can also occur due to backend API handling logic.

For example - I was trying to create an Nginx config file and restart the service by using the incoming API request body. This resulted in temporary disconnection of the Nginx service while handling the API request and resulted in socket hang up.

If you have tried all the steps mentioned in other comments, and still face the issue. I suggest you check the API handler code thoroughly.

I handled the above-mentioned example by calling the Nginx reset method with delay and a separate API to check the status of the prev reset request.

Cliffhanger answered 21/3, 2022 at 11:12 Comment(0)
P
0

For me it was giving Socket Hung Up error only while running Collection Runner not with single request. Adding a small delay (100-300ms) in the collection Runner solved issue for me.

Podite answered 3/8, 2022 at 10:19 Comment(0)
C
0

In my case, I had to provide --ssl-client-key and --ssl-client-cert files to overcome these errors.

Chinua answered 22/9, 2022 at 9:29 Comment(0)
A
0

Great error, it is so general that for everyone something different helps.

In my case I was not able to fix it and what is really funny is fact that I am expecting to get multipart file on one endpoint. When I prepare request in postman I get "Error: socket hang up". If I change for other endpoint(even not existing) is exactly that same error. But when I call any endpoint without body that request works and after that all subsequent attempts works perfectly.

In my case this is purely postman issue. Any request using curl is never giving that error.

Avidin answered 30/9, 2022 at 17:51 Comment(0)
P
0

in my case, it was Web postman client issue,

when i request GET on same condition on Postman App (not Web), it resolved

Permutation answered 20/4, 2023 at 15:27 Comment(0)
P
0

In my case it was due to the host name, my api url had the old host https://test-xyz.com/employee/1 so I changed it to https://test.xyz.net/employee/1.

So this error mostly occur due to the wrong url, check your url once and place the correct one before proceeding.

Persuasive answered 9/10, 2023 at 9:17 Comment(0)
L
0

DO NOT copy the request json from a whatsapp message, type with the kepboard or receive the endpoints as a colleciton. I got the same error for just one end point of the web service after updating the service. The web service was used to get no data at all and working fine. Then the requirement changed and we need to send 2 parameters to the API. My backend collegue, sent me the json over whatsapp: { "Id": 0, "AramaKriter": "ARA" }

When I copy the json from whatsapp and paste it to Postman raw area and sent the request, I got the socket hang up error. But when I re-type using the keyboard the API response was good as expected.

It seems that there are either missing blank chars or unseen chars that comes from whatsapp causes this interesting problem.

Lacee answered 31/1 at 15:21 Comment(0)
T
0

in my case, that was because of the Wrong URL, for example in the following URL

 {{base_url}}/users/{user_id}/report

I had an extra '}' in the URL. sometimes you might miss or have and extra curly brace, forward slash, typo and etc. so check the URL first.

Tommyetommyrot answered 6/3 at 6:16 Comment(0)
S
-1

I just solved this problem checking the hostname, It was bad written.

Steeplejack answered 6/12, 2023 at 16:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.