Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions modules/tftp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ def self.fetch_boot_file(dst, src)
def self.choose_protocol_and_fetch(src, destination)
case URI(src).scheme
when 'http', 'https', 'ftp'
::Proxy::HttpDownload.new(src.to_s, destination.to_s,
connect_timeout: Proxy::TFTP::Plugin.settings.tftp_connect_timeout,
verify_server_cert: Proxy::TFTP::Plugin.settings.verify_server_cert).start

thread = ::Proxy::HttpDownload.new(src.to_s, destination.to_s,
connect_timeout: Proxy::TFTP::Plugin.settings.tftp_connect_timeout,
verify_server_cert: Proxy::TFTP::Plugin.settings.verify_server_cert)
thread.start
thread
when 'nfs'
logger.debug "NFS as a protocol for installation medium detected."
else
Expand Down
11 changes: 10 additions & 1 deletion modules/tftp/tftp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ def create_default(variant)
end

post "/fetch_boot_file" do
log_halt(400, "TFTP: Failed to fetch boot file: ") { Proxy::TFTP.fetch_boot_file(params[:prefix], params[:path]) }
log_halt(400, "TFTP: Failed to fetch boot file: ") do
result = Proxy::TFTP.fetch_boot_file(params[:prefix], params[:path])

# fetch_boot_file may start a thread
# This waits for a bit before telling the client we've accepted it
# TODO: implement a mechanism to poll for completion
if result.respond_to(:join)
202 unless result.join(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming webrick is single threaded, does this mean that this will block for up to five seconds, preventing any other requests from being processed during that time?

Copy link
Member Author

Choose a reason for hiding this comment

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

Certainly a concern. I was debating this, how to make it configurable. But I also assumed we at least had some threads in Webrick. Yet I can't find proof for it. That may invalidate the whole approach.

Perhaps a mechanism similar to #472 to return a HTTP 202 with a task ID to poll for is a better approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

For an unrelated item I looked into this. Webrick has a single thread to accept clients, but then starts a thread for every client.

https://github.com/ruby/webrick/blob/cd0b1dd2286492287876773e719bb50a533d2698/lib/webrick/server.rb#L173-L194

So that would mean this just runs a sleep in its own thread, I don't see how it would be a problem.

Still, a proper task ID that can be monitored is a much better API. Both approaches aren't mutually exclusive though.

end
end
end

post "/:variant/create_default" do |variant|
Expand Down