67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/s3try.rb', line 67
def S3sync.S3try(command, bucket, *args)
if(not $S3syncHttp or (bucket != $S3syncLastBucket))
$stderr.puts "Creating new connection" if $S3syncOptions['--debug']
$S3syncLastBucket = bucket
while $S3syncRetriesLeft > 0 do
begin
S3sync.S3tryConnect(bucket)
break
rescue Errno::ECONNRESET => e
$stderr.puts "Connection reset: #{e}"
rescue Errno::ECONNABORTED => e
$stderr.puts "Connection aborted: #{e}"
rescue Errno::ETIMEDOUT => e
$stderr.puts "Connection timed out: #{e}"
rescue Timeout::Error => e
$stderr.puts "Connection timed out: #{e}"
end
$S3syncRetriesLeft -= 1
$stderr.puts "#{$S3syncRetriesLeft} retries left, sleeping for #{$S3SYNC_WAITONERROR} seconds"
Kernel.sleep $S3SYNC_WAITONERROR.to_i
end
end
result = nil
delim = $,
$,=' '
while $S3syncRetriesLeft > 0 do
$stderr.puts "Trying command #{command} #{bucket} #{args} with #{$S3syncRetriesLeft} retries left" if $S3syncOptions['--debug']
forceRetry = false
now = false
hush = false
begin
result = $S3syncConnection.send(command, bucket, *args)
rescue Errno::EPIPE => e
forceRetry = true
$stderr.puts "Broken pipe: #{e}"
rescue Errno::ECONNRESET => e
forceRetry = true
$stderr.puts "Connection reset: #{e}"
rescue Errno::ECONNABORTED => e
forceRetry = true
$stderr.puts "Connection aborted: #{e}"
rescue Errno::ETIMEDOUT => e
forceRetry = true
$stderr.puts "Connection timed out: #{e}"
rescue Timeout::Error => e
forceRetry = true
$stderr.puts "Connection timed out: #{e}"
rescue EOFError => e
forceRetry = true
$stderr.puts "EOF error: #{e}"
rescue OpenSSL::SSL::SSLError => e
forceRetry = true
$stderr.puts "SSL Error: #{e}"
rescue NoMethodError => e
$stderr.puts "Null stream error: #{e}"
break
end
if forceRetry
S3sync.S3tryConnect(bucket)
end
begin
debug("Response code: #{result.http_response.code}")
break if ((200...300).include? result.http_response.code.to_i) and (not forceRetry)
if result.http_response.code.to_i == 301
$stderr.puts "Permanent redirect received. Try setting AWS_CALLING_FORMAT to SUBDOMAIN"
elsif result.http_response.code.to_i == 307
host = %r{https?://([^/]+)}.match(result.http_response['Location'])[1]
$stderr.puts("Temporary Redirect to: " + host)
debug("Host: " + host)
S3sync.S3tryConnect(bucket, host)
$S3syncRetriesLeft = $S3syncRetriesLeft+1 forceRetry = true
now = true
hush = true
else
$stderr.puts "S3 command failed:\n#{command} #{args}"
$stderr.puts "With result #{result.http_response.code} #{result.http_response.message}\n"
debug(result.http_response.body)
end
break unless ((500...600).include? result.http_response.code.to_i) or forceRetry
rescue NoMethodError
debug("No result available")
end
$S3syncRetriesLeft -= 1
$stderr.puts "#{$S3syncRetriesLeft} retries left, sleeping for #{$S3SYNC_WAITONERROR} seconds" unless hush
Kernel.sleep $S3SYNC_WAITONERROR.to_i unless now
end
if $S3syncRetriesLeft <= 0
$stderr.puts "Ran out of retries; operations did not complete!"
end
$, = delim
result
end
|