chrisroberts / krakow

Ruby client library for NSQ
Other
99 stars 17 forks source link

TCP Socket not closing properly #34

Open fkruta opened 9 years ago

fkruta commented 9 years ago

Hello, I use krakow inside a rails app with ruby 2.2 MRE with krakow 0.4.2 and NSQ 0.3.5 I am creating and terminating a topic producer inside a controller to log some events that are reported by our mobile clients.

producer = Krakow::Producer.new(host: 'xx.xx.xx', port: 4150, topic: "#{@u_app_user.u_application_uid}")
producer.write(event_json)
producer.terminate

I noticed that after the connection is terminated in TCP connection remains in CLOSE_WAIT which btw can put the server down after the limit of max open socket/files is reached...For now I added a cron job to close the orphans connection in CLOSE_WAIT but this is not a solution to the problem...

# netstat -tonp 2>&1 | grep CLOSE
tcp       39      0 x.x.x.x:19689     x.x.x.x:4150        CLOSE_WAIT  -                off (0.00/0/0)
tcp       39      0 x.x.x.x:19689     x.x.x.x:4150        CLOSE_WAIT  -                off (0.00/0/0)
tcp       39      0 x.x.x.x:19689     x.x.x.x:4150        CLOSE_WAIT  -                off (0.00/0/0)
tcp       39      0 x.x.x.x:19689     x.x.x.x:4150        CLOSE_WAIT  -                off (0.00/0/0)
tcp       39      0 x.x.x.x:19689     x.x.x.x:4150        CLOSE_WAIT  -                off (0.00/0/0)
tcp       39      0x.x.x.x:19689     x.x.x.x:4150         CLOSE_WAIT  -                off (0.00/0/0)

Any ideas on finding a real fix ?

Thank you, BR