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

Cannot get an EC2 request ID #1038

Closed
abe4tawa8 opened this issue Dec 22, 2015 · 5 comments
Closed

Cannot get an EC2 request ID #1038

abe4tawa8 opened this issue Dec 22, 2015 · 5 comments
Assignees

Comments

@abe4tawa8
Copy link

This code cannot get an EC2 request ID.

region = "us-east-1"
client = Aws::EC2::Client.new(region: region)
response = client.describe_instances
response.context[:request_id]

=> nil

Aws::Plugins::Protocols::EC2#parse_xml method passes a block to Aws::Xml::Parser#parse method.
https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/aws-sdk-core/plugins/protocols/ec2.rb#L12-L21

          def parse_xml(context)
            if rules = context.operation.output
              data = Xml::Parser.new(rules).parse(xml(context)) do |h|
                context.metadata[:request_id] = h['requestId']
              end
              data
            else
              EmptyStructure.new
            end
          end

But Aws::Xml::Parser#parse method does not treat a block.
https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/aws-sdk-core/xml/parser.rb#L23-L31

      # @param [String] xml An XML document string to parse.
      # @param [Structure] target (nil)
      # @return [Structure]
      def parse(xml, target = nil)
        xml = '<xml/>' if xml.nil? or xml.empty?
        stack = Stack.new(@rules, target)
        @engine.new(stack).parse(xml.to_s)
        stack.result
      end

52f3efa#diff-91359190dca8b9e40db446ea5c1a5654

 -      # @param [String<xml>] xml
 -      # @param [Hash, nil] target
 +      # @param [String] xml An XML document string to parse.
 +      # @param [Structure] target (nil)
        # @return [Structure]
 -      def parse(xml, target = nil, &block)
 -        xml = MultiXml.parse(xml).values.first || {}
 -        yield(xml) if block_given?
 -        structure(@shape, xml, target)
 +      def parse(xml, target = nil)
 +        xml = '<xml/>' if xml.nil? or xml.empty?
 +        stack = Stack.new(@shape, target)
 +        @engine.new(stack).parse(xml)
 +        stack.result
        end
@awood45
Copy link
Member

awood45 commented Dec 22, 2015

Thanks for the report and details, will take a look at why this is happening.

@awood45 awood45 self-assigned this Dec 22, 2015
@awood45
Copy link
Member

awood45 commented Dec 23, 2015

Okay, pretty clear on things now, and can certainly see that the block is no longer being hit anywhere.

I'm looking in to the right fix now.

trevorrowe added a commit that referenced this issue Jan 14, 2016
This is a regression from when we switched to stream parsing the XML.
Older versions of the SDK parsed the entire XML document into a DOM,
and then walked that DOM to parse the values. Because the entire
document was no longer available in memory, the parser could no
longer yield it as a hash. This caused the EC2 protocol handler
to silently fail, no longer able to populate the request ID.

This update adds a callback to the XML parser that yields when
un-modeled/un-handled XML values are present in the response. The
EC2 handler registers a callback and checks the context/path
of the unhandled value and captures it if it is the request id.

To prevent a regression in the future, a unit test was added to ensure
the EC2 client correctly extracts the request id from the HTTP response
body and stores it in the response context.

Fixes #1038
@trevorrowe
Copy link
Member

I've submitted a PR that addresses this issue and adds a supporting test.

@trevorrowe
Copy link
Member

This has been merged and will be part of our next release.

@abe4tawa8
Copy link
Author

Thank you for fixing this issue. 😄

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

No branches or pull requests

3 participants