public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
263 stars 52 forks source link

HAFAS answers often with "ECONNRESET" #293

Closed VanDerLars closed 1 year ago

VanDerLars commented 1 year ago

Since some days we see the following behavior:

We make a call over Hafas Client and we get the following error message instead of the result: {"error":{"message":"request to https://reiseauskunft.bahn.de/bin/mgate.exe?checksum=660a896737929f3e112c5e5679151ba7 failed, reason: read ECONNRESET","type":"system","errno":"ECONNRESET","code":"ECONNRESET"}}

When we retry the exact same call one or two times, then the result comes often.

Also we monitor the Hafas Endpoint of Deutsche Bahn (reiseauskunft.bahn.de) with updown.io. The availability constantly got worse over the last weeks.

CleanShot 2023-06-23 at 09 12 31@2x

What could be the reason?

Do you know a way how to avoid the ECONNRESET error?

derhuerst commented 1 year ago

ECONNRESET is the error code that Node.js returns if the TCP has been closed unexpectedly, usually either due to a lossy connection or due to a firewall closing it or dropping packets.

It might be that they're rate-limiting requests from your servers' IP addresses. I've observed similar behaviour with my servers.

I would suggest

Also we monitor the Hafas Endpoint of Deutsche Bahn (reiseauskunft.bahn.de) with updown.io. The availability constantly got worse over the last weeks.

Do you monitor their endpoint directly, or do you monitor your API which pings their endpoint?

Issam-Jendoubi commented 1 year ago

Do you monitor their endpoint directly, or do you monitor your API which pings their endpoint?

We monitor their endpoint directly.

Actually, we were able to reproduce the issue locally. So, it seems that even if they have rate-limiting, it is not IP-based.

derhuerst commented 1 year ago

Actually, we were able to reproduce the issue locally. So, it seems that even if they have rate-limiting, it is not IP-based.

I'm not entirely sure about this. I've definitely run into IP-based rate limits even while developing locally, albeit with many requests. There might also be multiple limits in place, based on multiple factors.

derhuerst commented 1 year ago

I'll close this Issue, given that I don't have control over how HaCon and/or DB run the HAFAS endpoint.

You're very welcome to post more findings about the ECONNRESET errors though!

VanDerLars commented 1 year ago

what we see:

derhuerst commented 1 year ago

we "solved" by just retrying the same calls. the second, least the third attempt mostly work

Note that hafts-client provides retry.js for this. Its current logic merely aborts on ENOTFOUND errors and retries otherwise:

https://github.com/public-transport/hafas-client/blob/4cb70623025668a14d4493f3137711652e0089cc/retry.js#L15-L31

VanDerLars commented 1 year ago

@derhuerst thanks for the tipp.

@Issam-Jendoubi could ne a better approach, let's discuss that.