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

(PUP-11853) Wait for request completion before closing #9084

Merged

Conversation

tvpartytonight
Copy link
Contributor

Before this commit, puppet would attempt to finish a connection in the block passed to an http.request function. This will not work because finish sets the @socket to nil, and the net/http request assumes that the @socket is set for the duration of that function. With this change, we mark some state during the request function that indicates the connection should be closed after the completion of the http.request.

@tvpartytonight tvpartytonight requested a review from a team as a code owner July 7, 2023 18:48
@tvpartytonight
Copy link
Contributor Author

Still needs a specific test, but I believe this is the right approach.

@tvpartytonight tvpartytonight force-pushed the PUP-11853_close_after_request_done branch 2 times, most recently from 1f8df21 to be707d5 Compare July 10, 2023 18:18
Before this commit, puppet would attempt to `finish` a
connection in the block passed to an `http.request` function. This
will not work because `finish` sets the `@socket` to nil, and the
net/http request assumes that the `@socket` is set for the duration
of that function. With this change, we mark some state during the
request function that indicates the connection should be closed
after the completion of the `http.request`.
@tvpartytonight tvpartytonight force-pushed the PUP-11853_close_after_request_done branch from be707d5 to 7826d00 Compare July 10, 2023 19:31
@@ -175,6 +175,22 @@
end
end

context 'ensure that retrying does not attempt to read the body after closing the connection' do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running this test on 7.x, you can generate the original read body out of block error:

     Puppet::HTTP::HTTPError:
       Request to https://127.0.0.1:57572 failed after 1.01 seconds: attempt to read body out of block
     # ./lib/puppet/http/client.rb:455:in `raise_error'
     # ./lib/puppet/http/client.rb:166:in `rescue in connect'
     # ./lib/puppet/http/client.rb:136:in `connect'
     # ./lib/puppet/http/client.rb:366:in `execute_streaming'
     # ./lib/puppet/http/client.rb:275:in `post'
     # ./spec/integration/http/client_spec.rb:189:in `block (4 levels) in <top (required)>'
     # ./spec/lib/puppet_spec/https.rb:81:in `block in start_server'
     # ./spec/lib/puppet_spec/https.rb:41:in `pipe'
     # ./spec/lib/puppet_spec/https.rb:41:in `start_server'
     # ./spec/integration/http/client_spec.rb:186:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:180:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.7.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # IOError:
     #   attempt to read body out of block
     #   ./lib/puppet/http/response_net_http.rb:18:in `body'

@joshcooper joshcooper merged commit cb7a659 into puppetlabs:7.x Jul 10, 2023
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants