"Cannot assign requested address": your server ran out of ports
transcript
Your service is fine. One minute later, every database call fails. The error: cannot assign requested address. And the database is fine.
Here's the code. Every query opens a fresh connection. 500 a second. Every outbound connection takes a port on your machine. Query done, connection closed. Port free? No. The side that closed waits in time wait. 60 seconds on Linux. The port stays taken.
500 a second, each held for 60 seconds. You need 30,000 ports. Linux gives you about 28,000 by default. The official range? About 16,000. Either way, you run out.
Here's the twist. The database never refused you. A database limit is a refusal from the server. This error is local. Your own machine ran dry.
Without a pool, every query pays a handshake, and leaves a port behind. The fix is a connection pool. Keep connections open and reuse them. It caps the total, so ports can't run out. 10 to 50, for a database.
Opening costs a handshake. Closing costs a port for a minute. So don't open per query. Pool it.
Full breakdown in the lecture.