I don't know what the optirun command does to set the DISPLAY env variable.. but on my machine, when I don't set the DISPLAY variable to something useful I get the message
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 146 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 22
Current serial number in output stream: 22
Segmentation fault (core dumped)
for reference, your error messages was slightly different from mine..
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 72 (X_PutImage)
Serial number of failed request: 38
Current serial number in output stream: 40
Error [Transport.cc:102] Unable to get topic namespaces in [50] tries.
Error [Node.cc:68] No namespace found
To fix my problem, I run xvfb (can be run in the background or in another terminal)
Xvfb :1 -screen 0 1024x768x24
and then run gazebo
DISPLAY=:1 rosrun gazebo gazebo
my.world
If there was a display already open on the machine that I had access to (e.g. if I was physically logged in through a GUI or something), I could have also set the variable to that value as well.