Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper method for handling random network timeouts #89

Open
postmodern opened this issue Oct 26, 2023 · 4 comments
Open

Add a helper method for handling random network timeouts #89

postmodern opened this issue Oct 26, 2023 · 4 comments
Labels
idea Random idea

Comments

@postmodern
Copy link
Member

postmodern commented Oct 26, 2023

It appears that Async::HTTP::Internet.instance can raise an Errno::ETIMEDOUT exception when the connection to the HTTP server times out. We should decide whether to ignore timeouts, or add a helper method that can retry the given block possibly with a sleep(1) delay and incremental counter. Such a helper method could be provided by a Ronin::Recon::Mixins::Retry mixin module.

Pseudocode

def retry_on_timeout(limit: 3, &block)
  retries = 0

  begin
    block.call
   rescue Errno::ETIMEDOUT => error
    sleep(1)
    retries += 1
    if retries > limit
      raise(error)
    else
      retry
    end
  end
end
@postmodern postmodern added the idea Random idea label Oct 26, 2023
@postmodern
Copy link
Member Author

Appears there's similar code in lib/ronin/recon/builtin/web/dir_enum.rb. Could extract that code into a Mixin and helper method.

begin
response = http.head(url)
if RESOURCE_STATUS_CODES.include?(response.status)
yield URL.new(url, status: response.status,
headers: response.to_h)
end
rescue Errno::ECONNREFUSED,
SocketError
task.stop
rescue StandardError
if retries > 3
next
else
retries += 1
sleep 1
retry
end

@moozzi
Copy link
Member

moozzi commented Oct 29, 2023

Should this new Mixin be included in CertSh and DirEnum classes or somewhere higher?
Also should it catch Errno::ETIMEDOUT or just StandardError?

@moozzi
Copy link
Member

moozzi commented Oct 29, 2023

Or should we include it just in CertSh?

@moozzi moozzi mentioned this issue Oct 29, 2023
@postmodern
Copy link
Member Author

postmodern commented Oct 29, 2023

@AI-Mozi that is a good question. I would say only include it where we are currently needing to handle network timeouts and retries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Random idea
Projects
None yet
Development

No branches or pull requests

2 participants