Skip to content

Commit

Permalink
Disable auto retry by net/http
Browse files Browse the repository at this point in the history
Because GET isn't idempotent in Groonga such as delete command.
  • Loading branch information
kou committed Oct 27, 2017
1 parent 1a4aae6 commit fee23f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
6 changes: 0 additions & 6 deletions bin/groonga-client
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "net/http"

if Net::HTTP.const_defined?(:IDEMPOTENT_METHODS_)
Net::HTTP::IDEMPOTENT_METHODS_.clear
end

require "groonga/client/command-line/groonga-client"

command_line = Groonga::Client::CommandLine::GroongaClient.new
Expand Down
6 changes: 0 additions & 6 deletions bin/groonga-client-index-recreate
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "net/http"

if Net::HTTP.const_defined?(:IDEMPOTENT_METHODS_)
Net::HTTP::IDEMPOTENT_METHODS_.clear
end

require "groonga/client/command-line/groonga-client-index-recreate"

command_line = Groonga::Client::CommandLine::GroongaClientIndexRecreate.new
Expand Down
23 changes: 22 additions & 1 deletion lib/groonga/client/protocol/http/synchronous.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ class Client
module Protocol
class HTTP
class Synchronous
# TODO: Workaround to disable retry in net/http.
class HTTPClient < Net::HTTP
class ReadTimeout < StandardError
end

module ReadTimeoutConvertable
def rbuf_fill
begin
super
rescue Net::ReadTimeout => error
raise ReadTimeout, error.message, error.backtrace
end
end
end

private
def on_connect
@socket.extend(ReadTimeoutConvertable)
end
end

include PathResolvable

def initialize(url, options={})
Expand All @@ -36,7 +57,7 @@ def initialize(url, options={})

def send(command)
begin
Net::HTTP.start(@url.host, @url.port, start_options) do |http|
HTTPClient.start(@url.host, @url.port, start_options) do |http|
http.read_timeout = read_timeout
response = send_request(http, command)
case response
Expand Down

0 comments on commit fee23f2

Please sign in to comment.