Messing with local ports

Being able to develop stuff locally is certainly on of the points I love the most working with Azure and Python. Later, you can hyper-scale the shit out of your code, but you can also debug it first on your tiny machine.

if __name__ == '__main__':
    # This code only runs when executing the script directly (not on App Service)
    logging.info("Starting Flask app in local development mode")
    socketio.run(app, host='0.0.0.0', port=5000, debug=True)

This piece of code is probably run a thousand times every day by a thousand developers. However, it was quite difficult to find an easy answer on google for this:

OSError: [Errno 48] Address already in use: ('0.0.0.0', 5000)

Easy to understand what it means, like port 5000 is in use already. WTF? Who is running something on my machine???

Of course, me. Another PyCharm window or something. But no, not this time. Strange. `netstat to the rescue 🙂 Well, not on macOS.

For whatever reason it cannot show you ports in LISTEN, at least that I could find. But how can we figure it out? lsof can help us here:

lsof -i :5000
COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
ControlCe 650 trueal   10u  IPv4 0xa162a6f756348686      0t0  TCP *:commplex-main (LISTEN)
ControlCe 650 trueal   11u  IPv6  0x2c61017c47991be      0t0  TCP *:commplex-main (LISTEN)

WTF is a commplex? Another round of googling shows it belongs to AirPlay. So technically, ever developer on macOS should not be able to run the demo code?? So at least now you know, too, what is hogging your precious port 5000. You’re welcome.

WordPress Admin Panel extremely slow

Hosting a blog yourself is certainly one of the best things to do. Not only will you have full control of your data, but you will certainly learn a lot about technology along the way.

So today I decided to start writing a blog, once more, and hosting it myself. Here. Post 1.

But the /wp-admin/ panel is so painfully slow. The pages take up to six seconds to load.

But how can you figure out what is happening? I mean, sure, it could be my server. It’s just a Synology with a simple 4 core CPU.
But then, it’s just PHP?

So I found this nice plugin for WordPress, called Query Monitor. I will be visible in the top bar of the admin panel and show you exactly what is happening. And I found that:

cURL error 28: Resolving timed out after 3001 milliseconds

Seems like the admin panel is trying to connect to http://api.wordpress.org/translations/core/1.0/ and is running into a timeout.

Strange. Connecting via ssh and running a nslookup is also slow as hell. So it really seems, that the DNS lookup is somehow broken. In my setup, my router (a FritzBox) is causing the delay in DNS lookups.

Solution: Switching to public DNS servers 1.1.1.1 and 8.8.8.8 in the DSM settings, and problems all gone.

Next step: run a proper DNS caching server at home. I think it will be PiHole, but that’s another blog post 🙂