Class: Aws::Plugins::Retries::ClockSkew Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/plugins/retries/clock_skew.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

CLOCK_SKEW_THRESHOLD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

five minutes

5 * 60

Instance Method Summary collapse

Constructor Details

#initializeClockSkew

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ClockSkew.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 10

def initialize
  @mutex = Mutex.new
  # clock_corrections are recorded only on errors
  # and only when time difference is greater than the
  # CLOCK_SKEW_THRESHOLD
  @endpoint_clock_corrections = Hash.new(0)

  # estimated_skew is calculated on every request
  # and is used to estimate a TTL for requests
  @endpoint_estimated_skews = Hash.new(nil)
end

Instance Method Details

#clock_correction(endpoint) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the clock_correction in seconds to apply to a given endpoint

Parameters:

  • endpoint (URI, String)


24
25
26
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 24

def clock_correction(endpoint)
  @mutex.synchronize { @endpoint_clock_corrections[normalized_endpoint(endpoint)] }
end

#clock_skewed?(context) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines whether a request has clock skew by comparing the current time against the server’s time in the response

Parameters:

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 42

def clock_skewed?(context)
  server_time = server_time(context.http_response)
  !!server_time &&
    (Time.now.utc - server_time).abs > CLOCK_SKEW_THRESHOLD
end

#estimated_skew(endpoint) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The estimated skew factors in any clock skew from the service along with any network latency. This provides a more accurate value for the ttl, which should represent when the client will stop waiting for a request. Estimated Skew should not be used to correct clock skew errors it should only be used to estimate TTL for a request



35
36
37
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 35

def estimated_skew(endpoint)
  @mutex.synchronize { @endpoint_estimated_skews[normalized_endpoint(endpoint)] }
end

#update_clock_correction(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Called only on clock skew related errors Update the stored clock skew correction value for an endpoint from the server’s time in the response

Parameters:



52
53
54
55
56
57
58
59
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 52

def update_clock_correction(context)
  endpoint = context.http_request.endpoint
  now_utc = Time.now.utc
  server_time = server_time(context.http_response)
  return unless server_time && (now_utc - server_time).abs > CLOCK_SKEW_THRESHOLD

  set_clock_correction(normalized_endpoint(endpoint), server_time - now_utc)
end

#update_estimated_skew(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Called for every request Update our estimated clock skew for the endpoint from the servers time in the response

Parameters:



65
66
67
68
69
70
71
72
73
74
# File 'lib/aws-sdk-core/plugins/retries/clock_skew.rb', line 65

def update_estimated_skew(context)
  endpoint = context.http_request.endpoint
  now_utc = Time.now.utc
  server_time = server_time(context.http_response)
  return unless server_time

  @mutex.synchronize do
    @endpoint_estimated_skews[normalized_endpoint(endpoint)] = server_time - now_utc
  end
end