Skip to content

Commit 0e7b6d1

Browse files
committed
Add a timeout for sandbox posts
1 parent 477bc6c commit 0e7b6d1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

app/models/remote_sandbox.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'rest_client'
44
require 'submission_packager'
5+
require 'timeout'
56

67
# Represents a connection to a remote machine running the tmc-sandbox web service.
78
#
@@ -57,9 +58,13 @@ def send_submission(submission, notify_url)
5758

5859
File.open(tar_path, 'r') do |tar_file|
5960
Rails.logger.info "Posting submission to #{post_url}"
60-
RestClient::Request.execute(method: :post, url: post_url, timeout: 5, payload: {
61-
file: tar_file, notify: notify_url, token: submission.secret_token
62-
})
61+
# While Timeout::timeout is considered dangerous, this is still necessary because if this happens to block it will bring the whole server down.
62+
Timeout.timeout(10) do
63+
# The timeout is only for open_timeout and read_timeout
64+
RestClient::Request.execute(method: :post, url: post_url, timeout: 5, payload: {
65+
file: tar_file, notify: notify_url, token: submission.secret_token
66+
})
67+
end
6368
submission.sandbox = post_url
6469
submission.save!
6570
rescue StandardError => e

0 commit comments

Comments
 (0)