For a long time, when using my computer (Arch linux), I would sometimes run into this problem. When trying to open an application in a new window, I’ll be met by:

Invalid MIT-MAGIC-COOKIE-1 key
cannot open display: :0

I’ve tried a lot of “solutions” without luck, but I’ve finally found a way to consistently reproduce the error. It happens everytime I connect to a new wifi.

I found this 9 year old post about the same problem, but it does not include a real solution or the cause of the problem.

I’ll try asking it here, to see if anybody knows why it happens and how to solve it, and perhaps to help others with the same problem find the cause of this error. It is such a relief for me, knowing that it is caused by changing wifi.

In advance, thanks for the help/feedback :)