If this blog helped you in any way (professionally), please donate a dollar here

Sunday, November 16, 2014

Removing CLOSE_WAIT connections

Hello folks, just thought I would share something I came with during one fine day at work.

Recently, we faced a problem where there were a lot of CLOSE_WAIT connections on our server which caused a variety of issues on the server. It seemed like there was a bug in the application (a java based app) but hunting it down was a pain, fixing it would also take a long time. Instead what we did, was to restart the application at periodic intervals which seemed to clean up the CLOSE_WAIT connections.

However, we wanted to remove CLOSE_WAIT connections without killing the process. We found that we could do the same with tools like :
We tried them out but none of them seemed to be of much use for CLOSE_WAIT connections. So I hacked into the source code of killcx and found this interesting bit of code:
my $packet = Net::RawIP->new({
      ip => {  frag_off => 0, tos => 0,
               saddr => $dest_ip, daddr => $local_ip
            },
      tcp =>{  dest => $local_port, source => $dest_port,
               seq => 10, syn => 1
            }
   });
   $packet->send;
I modified this and wrote this utility that removes all CLOSE_WAIT connections: https://github.com/rghose/kill-close-wait-connections

This seemed to do the trick! Happy hacking.

Sunday, November 2, 2014

Identifying the actor

So, here I am at Candies, Bandra looking at an all too familiar Bollywood actor, who was also a customer there. He played the villain or cop in many movies, I know him. He had his son with him as well. They bear an uncanny resemblance. I want to go up there and get a picture clicked with him. Wait, what was his name?

I asked my friend who was with me, he too seemed clueless. He also wanted to get a picture clicked, but what if he asked his name? We were terrified of that prospect, as we saw a young woman probably in her 30s, go up to him and click one herself. Damn. Shes knows his name for sure.

In our dilemma and brain racking to recollect his name, he was done with his buying and he left. Leaving me pondering over this problem of his identity. So I came home and tried searching Google, assuming it will read my brainwaves. No use. I could not find a Bollywood actor who visited Candies often, he was not a very well known figure like say, Shahrukh Khan for instance, but he was pretty well known. Now I decided to do this: http://en.wikipedia.org/wiki/List_of_Indian_film_actors!

Again, there were too many! So I made these:

a) Python script to get the images from an infobox element in a page here.
b) Shell script to automate this here.

Armed with these tools, I did this:
# wget http://en.wikipedia.org/wiki/List_of_Indian_film_actors
# grep '<li><a href=' List_of_Indian_film_actors | grep 'title' > list
Deleted the last irrelevant line and fired up "./parse_names.sh list"

I made myself some coffee, came back to my laptop and casually started browsing the thumbnails from my file manager. Found him!