• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do you kill and block network connectivity on specific port including existing sessions?

Red Squirrel

No Lifer
I am troubleshooting an issue with an application where when it loses connectivity to the SQL server, it crashes. There's some random slowdowns that happen on my network all the time that cause this to happen, and while I gave up on trying to figure out what causes the slowdowns, I just want to make it so the application stops crashing when it happens. So basically I want to simulate loss of connectivity by running a script on the SQL server where it will kill existing connections as well as block new ones. From the application's point of view it will be like if the connection dropped which will allow me to troubleshoot my code as I'll be able to make it crash at will, then work on the code and keep testing until I solve the issue.

Adding a new IP tables rules does not account for existing connections and simply stopping the SQL service is not enough, because it will gracefully end any transactions and do cleanup, it needs to be a hard disconnect. I can't disable the network interface either, because the file system is on that same server and I don't want to affect that, just mysql connectivity.

I googled and found something called tcpkill but it's not in the repository for my distro (CentOS). I'm also not sure if it will do what I want as i think it actually sends a disconnect packet to the client. I need it to be more abrupt. Any ideas?

Worse case scenario suppose I can separate SQL from storage, and then just do the nic disable idea.
 
Last edited:
I had googled too but didn't know what package name was suppose to be called. Had to install a rpm for that command to work but now I have it. The tcpkill command works now, so I'll have to experiment with it.
 
You could have the SQL server on one port, point your application to another port, and have a socat in the middle, which you can kill at will.

I can never remember the socat syntax, so I have a script "tcp_relay host_port dest_server dest_port":
Code:
socat tcp-listen:$1,reuseaddr,fork tcp-connect:$2:$3
 
So this appears to be working as I wanted to. Was able to simulate connectivity blips. If I wanted the blips to last long I just kept it running, or blocked in firewall in addition to running it. For short blips I'd run it and stop it as soon as I see tcpdump output.
 
Back
Top