I used Axios to make post request to a remote server. This is the code below
import axios from 'axios';
import Agent from 'agentkeepalive';
import http from 'http';
import https from 'https';
//keepAlive pools and reuses TCP connections, so it's faster
const keepAliveAgent = new Agent({
maxSockets: 100, // Maximum number of sockets to allow per host. Defaults to Infinity.
maxFreeSockets: 10,
timeout: 60000, // active socket keepalive for 60 seconds
freeSocketTimeout: 60000, // // Maximum number of sockets to leave open for 60 seconds in a free state. Only relevant if keepAlive is set to true. Defaults to 256.
socketActiveTTL: 1000 * 60 * 10,
});
const axiosInstance = axios.create({ httpAgent: keepAliveAgent });
After that, I import into the file below to make the call
import { axiosInstance} from './axiosInstance';
let responseBody = await axiosInstance.post(ROOT_URI, prepareFormData(filename, file), {
headers: form.getHeaders(),
});
Then I'm guessing there's something weird in the way you're building the URLs or making the requests when there are multiple API calls.
To clean things up, if I was you I'd change the code to use map() on the array of cvUrl returning a promise for each call.
The await promise.all() on the result of that map, then do your parsing.
Put console.logs in each iteration to determine exactly what you're sending and wrap in try/catch to see if you can find any more information about what's actually going wrong with the connection.
@ross
Coundon, I would appreciate your assistance from the wealth of your experience in the field interacting with several third part API on how I can make a concurrent request to the server without experience the "socket hangout issue". In the first interaction of the loop shown above, I will get results from the third-party API but on the second iteration, there will be a delay for a response from the third party and hence the error message below
Trace: { Error: socket hang up
at createHangUpError (_http_client.js:323:15)
at TLSSocket.socketOnEnd (_http_client.js:426:23)
at TLSSocket.emit (events.js:194:15)
at TLSSocket.EventEmitter.emit (domain.js:441:20)
at endReadableNT (_stream_readable.js:1125:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
Hi - I'm not sure what to suggest, are you able to share what the 3rd party API is? Do they provide any documentation/information on acceptable usage, time between requests, number of concurrent requests etc?
They do not have that spell out on their API documentation. I have sent a mail to them to inquire about the acceptable usage, the time between requests, number of concurrent requests
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I used Axios to make post request to a remote server. This is the code below
After that, I import into the file below to make the call
Can you try with a raw axios instance, i.e. without the KeepAliveAgent?
I have done that. It was after some research that I added KeepAliveAgent to see whether it can be solved but still proved abortive
How about making a single, non-bottlenecked call to the API? Does that work?
Making a single call even with bottleneck works perfectly
Then I'm guessing there's something weird in the way you're building the URLs or making the requests when there are multiple API calls.
To clean things up, if I was you I'd change the code to use map() on the array of cvUrl returning a promise for each call.
The await promise.all() on the result of that map, then do your parsing.
Put console.logs in each iteration to determine exactly what you're sending and wrap in try/catch to see if you can find any more information about what's actually going wrong with the connection.
This is where I tried it with Promise.all but got the same error. Is this code below look like what you suggested above?
I need your assistance to get this resolve. Thanks
@ross Coundon, I would appreciate your assistance from the wealth of your experience in the field interacting with several third part API on how I can make a concurrent request to the server without experience the "socket hangout issue". In the first interaction of the loop shown above, I will get results from the third-party API but on the second iteration, there will be a delay for a response from the third party and hence the error message below
Hi - I'm not sure what to suggest, are you able to share what the 3rd party API is? Do they provide any documentation/information on acceptable usage, time between requests, number of concurrent requests etc?
They do not have that spell out on their API documentation. I have sent a mail to them to inquire about the acceptable usage, the time between requests, number of concurrent requests