Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cause: Error: socket hang up when try to send many requests #24

Open
CentralMatthew opened this issue Apr 3, 2023 · 1 comment
Open

Comments

@CentralMatthew
Copy link

I need to translate a lot of data, when i try to do translate in loop i got this error. How i can prevent this?

ConnectionError: Connection failure: socket hang up
at Function.sendAxiosRequest (/Users/matthew/IdeaProjects/backend/node_modules/deepl-node/dist/client.js:163:27)
at runMicrotasks ()
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async HttpClient.sendRequestWithBackoff (/Users/matthew/IdeaProjects/backend/node_modules/deepl-node/dist/client.js:114:28)
at async Translator.translateText (/Users/matthew/IdeaProjects/backend/node_modules/deepl-node/dist/index.js:354:41)
at async /Users/matthew/IdeaProjects/backend/lib/utils/formatDocsJSON.js:156:17
at async Promise.all (index 45)
at async /Users/matthew/IdeaProjects/backend/lib/utils/formatDocsJSON.js:140:16
at async Promise.all (index 3)
at async formatJsonFile (/Users/matthew/IdeaProjects/backend/lib/utils/formatDocsJSON.js:139:18)
at async main (/Users/matthew/IdeaProjects/backend/lib/utils/formatDocsJSON.js:34:5) {
error: AxiosError: socket hang up
at Function.AxiosError.from (/Users/matthew/IdeaProjects/backend/node_modules/axios/dist/node/axios.cjs:789:14)
at RedirectableRequest.handleRequestError (/Users/matthew/IdeaProjects/backend/node_modules/axios/dist/node/axios.cjs:2744:25)
at RedirectableRequest.emit (node:events:525:35)
at ClientRequest.eventHandlers. (/Users/matthew/IdeaProjects/backend/node_modules/follow-redirects/index.js:14:24)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketOnEnd (node:_http_client:518:9)
at TLSSocket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ECONNRESET',
config: {
transitional: [Object],
adapter: [Array],
transformRequest: [Array],
transformResponse: [Array],
timeout: 20000,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: null,
headers: [AxiosHeaders],
url: '/v2/translate',
method: 'post',
baseURL: 'https://api.deepl.com',
responseType: 'text',
data: 'target_lang=en-US&source_lang=de&text=Apikoaortales%2C+klappentragendes+Konduit'
},
request: Writable {
_writableState: [WritableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 79,
_requestBodyBuffers: [Array],
_onNativeResponse: [Function (anonymous)],
_currentRequest: [ClientRequest],
_currentUrl: 'https://api.deepl.com/v2/translate',
_timeout: null,
[Symbol(kCapture)]: false
},
cause: Error: socket hang up
at connResetException (node:internal/errors:705:14)
at TLSSocket.socketOnEnd (node:_http_client:518:23)
at TLSSocket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ECONNRESET'
}
},
shouldRetry: false
}

This is my configutration deepl.Translator(config.deeplApiKey, { maxRetries: 50, minTimeout: 20000 });

@JanEbbing
Copy link
Member

JanEbbing commented Apr 3, 2023

Hi, could you share the code (the for loop) please?
I would guess this either happens when the API is down/the server crashes or something similar, maybe it can also happen when you send too many requests in a short timeframe.

I would recommend two things:
a) If you have many small texts, bundle them in one request - translateText accepts an array (translateText(["Hallo Welt", "Hello World"], "PL")) with up to 50 entries.
b) If that doesn't solve the problem, add some client-side rate limiting if you send too many requests at once (if you have many texts and your for loop is written asynchronously, you could be launching hundreds of requests in parallel, which would explain this error - you want to have a parameter that controls how many parallel connections you can have at most).

We will support b) better in the future, this is a feature we are working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants