We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

Convert DOCX to PDF in Ruby throws timeout error

Hi,

We have been using aspose words cloud API for ruby and sometimes face timeouts on the conversion requests (Convert Documents). It happens randomly and then for the same file, it works. Please suggest a solution to this or a better way to approach it? I am also including the error logs with this post.

   **Error occurred:** Net::ReadTimeout with #<TCPSocket:(closed)> **on 07 December 2021 08:05 PM**
    /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:217:in `rbuf_fill' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:191:in `readuntil' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:201:in `readline' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http/response.rb:42:in `read_status_line' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http/response.rb:31:in `read_new' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1528:in `block in transport_request' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1519:in `catch' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1519:in `transport_request' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1492:in `request' 
/app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/instruments/net_http.rb:30:in `block in request_with_scout_instruments' 
/app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/tracer.rb:34:in `instrument' 
/app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/tracer.rb:44:in `instrument' 
/app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/instruments/net_http.rb:29:in `request_with_scout_instruments' 
/app/vendor/bundle/ruby/2.7.0/gems/sentry-ruby-core-4.7.3/lib/sentry/net/http.rb:38:in `request' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:152:in `block in request_via_request_method' 
/app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:933:in `start' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:146:in `request_via_request_method' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:131:in `request_with_wrapped_block' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:122:in `perform_request' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:66:in `block in call' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/adapter.rb:50:in `connection' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:64:in `call' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/request/url_encoded.rb:25:in `call' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/request/multipart.rb:30:in `call' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/rack_builder.rb:154:in `build_response' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/connection.rb:516:in `run_request' 
/app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/connection.rb:281:in `put' 
/app/vendor/bundle/ruby/2.7.0/gems/aspose_words_cloud-21.9.0/lib/aspose_words_cloud/api_client.rb:153:in `build_request' 
/app/vendor/bundle/ruby/2.7.0/gems/aspose_words_cloud-21.9.0/lib/aspose_words_cloud/api_client.rb:78:in `call_api' 
/app/vendor/bundle/ruby/2.7.0/gems/aspose_words_cloud-21.9.0/lib/aspose_words_cloud/api/words_api.rb:1072:in `convert_document_with_http_info' 
/app/vendor/bundle/ruby/2.7.0/gems/aspose_words_cloud-21.9.0/lib/aspose_words_cloud/api/words_api.rb:1020:in `convert_document' 
/app/lib/tape.rb:39:in `merge' 
/app/app/jobs/update_instruction_report_job.rb:26:in `update_report' 
/app/app/jobs/update_instruction_report_job.rb:12:in `perform' 
/app/vendor/bundle/ruby/2.7.0/gems/activejob-6.1.4.1/lib/active_job/execution.rb:48:in `block in perform_now' 
/app/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks' /app/app/jobs/application_job.rb:4:in `block (2 levels) in <class:ApplicationJob>' 
/app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/connection_adapters/abstract/query_cache.rb:79:in `uncached' 
/app/vendor/bundle/ruby/2.7.0/gems/activerecord-6.1.4.1/lib/active_record/query_cache.rb:21:in `uncached' /app/app/jobs/application_job.rb:3:in `block in <class:ApplicationJob>' 
/app/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:126:in `instance_exec' 
/app/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks' 
/app/vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.7.3/lib/sentry/rails/active_job.rb:9:in `block (2 levels) in included' 
/app/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:126:in `instance_exec' 
/app/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks' 

@nikhilgoyal2205

We are sorry for the inconvenience. I am afraid we have not received any other similar complaint recently. Please share some more details; sample code and input files. We will try to replicate the issue at our end and share our findings with you.

Furthermore, please also note that Aspose.Words Cloud API does not support concurrent requests for the same document. You can call any number of requests independently for different documents.

Hi,
We are doing nothing crazy in our code. It’s very simple as per your documentation

@words_api = AsposeWordsCloud::WordsApi.new
convert_request = AsposeWordsCloud::ConvertDocumentRequest.new(document: File.open(output_doc), format: 'pdf')
@words_api.convert_document(convert_request)

Since the default timeout is 60 seconds, some requests timeout but the same request works again after some time or 2nd/3rd time. As I have stated earlier that this happens sporadically and with no specific file. I am attaching a sample document for the usage (OutputDoc.docx (7.4 MB))

I would suggest doing requests one after the other to reproduce the issue. Also, wanted to know a scenario of say 10 users on the system doing requests for different documents.

Let me know if you want anything else from my side.

Thanks

@nikhilgoyal2205

Thanks for sharing the sample Word document. I have tested the conversion in a loop as follows but I am afraid still unable to reproduce the issue. Please ensure you are using the latest version of Aspose.Words Cloud SDK for Ruby. And if you still face the issue then please share your working code with us to replicate the issue at our end.

require 'aspose_words_cloud'

class Document

  include AsposeWordsCloud

  # Get App key and App SID from https://dashboard.aspose.cloud/
  APP_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  APP_SID = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"

  def initialize
    AsposeWordsCloud.configure do |config|
      config.client_data['ClientId'] = APP_SID
      config.client_data['ClientSecret'] = APP_KEY
	  end
    @words_api = WordsApi.new
  end

  # Convert locatl file
  def test_convert_document
      request_document = File.open('C:/Temp/OutputDoc.docx')
      request = ConvertDocumentRequest.new(document: request_document, format: 'pdf')
      result = @words_api.convert_document(request)	  
end
end

document = Document.new()

# using for loop
for i in 1..10 do
     puts document.test_convert_document
	 puts i
  
end

Yes, Aspose.Words Cloud API will work when 10 users are requesting 10 different documents.