Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8472255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:00:50+00:00 2026-06-10T17:00:50+00:00

I have a small script which scans all the ips ranging from 192.168.190.xxx to

  • 0

I have a small script which scans all the ips ranging from 192.168.190.xxx to 192.168.220.xxx on port 411.

The script works fine sometimes, but sometimes I get the error “No buffer space available”
dcport.rb:8:ininitialize’: No buffer space available – connect(2) (Errno::ENOBUFS)`

I have read that this occurs when the socket were not closed properly, but I have used mysocket.close to prevent that which I suppose does not work properly.

How to prevent this from happening, I mean how to close the socket properly?

My code is as follows

require 'socket'
require 'timeout'
(190...216).each do |i|
  (0...255).each do |j|
    begin
      #puts "Scanning 192.168.#{i}.#{j}"
      scan=Timeout::timeout(10/1000.0) {
        s=TCPSocket.new("192.168.#{i}.#{j}",411)
        s.close
        puts "192.168.#{i}.#{j} => Hub running"
      }
    rescue Timeout::Error
    rescue Errno::ENETUNREACH
    rescue Errno::ECONNREFUSED
    end
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:00:51+00:00Added an answer on June 10, 2026 at 5:00 pm

    My guess is that, sometimes, the timeout fires between the socket creation and the socket closing, which makes you leak some sockets. Since (as far as a quick google search told me), ENOBUFS happens by default after 1024 sockets opened, that could definitely be it.

    Timeout, as well as Thread.raise, is very harmful in situations where you need to be sure that something happens (in your case, s.close), as you actually cannot guarantee it anymore: the exception could be raised anywhere, even within an ensure block.

    In your case, I think that you could fix it by adding an ensure clause outside the timeout block (untested code follows):

    require 'socket'
    require 'timeout'
    (190...216).each do |i|
      (0...255).each do |j|
        begin
          #puts "Scanning 192.168.#{i}.#{j}"
          s = nil
          scan=Timeout::timeout(10/1000.0) do
            s=TCPSocket.new("192.168.#{i}.#{j}",411)
            puts "192.168.#{i}.#{j} => Hub running"
          end
        rescue Timeout::Error
        rescue Errno::ENETUNREACH
        rescue Errno::ECONNREFUSED
        ensure
          s.close if s
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small PHP script which has $query = SELECT MAX(id) FROM `dbs`; //query
I have written a small batch script which copies files from the a folder
I have a small script which retrieves the LastLogonTimestamp and the SAMAccount for all
I have written a small php script which reads file names from a directory,
I have a small script which im using to test PHP mail(), as below:
I have a small python script which draws some turtle graphics. When my script
I have small script in bash, which is generating graphs via gnuplot. Everything works
I have a small ruby script in which I'd like to use ActiveRecord to
I have a small script and want to detect the script version from admin
I have a small script that I am try to port to work for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.