Double IPs in the wild

We had a small percentage of users running into 502 errors for a while, which is not surprising with the amount of traffic we have.

The recurring theme was that almost all of them used a VPN in some capacity. And as much as VPNs advertise about hiding your ass, they sometimes are more honest than they should be.

One of the more important features of MangaDex is to automatically assign you to the image server closest to you. For that we need GeoIP to figure out on which continent and in which country you are. Based on that we direct you to the best server we believe you have the lowest latency to.

Because some VPNs are *very* honest, they give us more than one IP address. 99% of our traffic sends us something like this as the connecting user IP: 88.53.74.1
The honest VPNs sent us this: 88.53.74.1, 174.88.6.54

While we did have a protection mechanism in place to find the most sensical IP from what we know about a user, we unfortunately did not cover this exact format. The GeoIP library threw an Exception which we did not catch and that caused the 502 Error.

Today’s changes make sure that if any IP contains a “,” we use the first IP as the connecting user’s IP.