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.

@tilal.ahmad its been happening sporadically but it happened 3 times back to back yesterday even when I have increased the timeout using config.timeout = 120, it still timed out after 60 sec. Also, the cloud dashboard doesn’t show anything related to these requests. Below is an example of error

Feb 23 20:24:42 Surventrix2.0 app/worker.1 E, [2022-02-23T14:54:41.359728 #1976] ERROR -- : [ActiveJob] [SignOffStatusJob] [4c5ba9b6-4098-4293-979f-642f38f329fc] [UpdateInstructionReportJob] [78534f73-590f-44f1-814c-8cc094810bc4] Error performing UpdateInstructionReportJob (Job ID: 78534f73-590f-44f1-814c-8cc094810bc4) from Resque(surventrix_production_default) in 68633.73ms: Faraday::TimeoutError (Net::ReadTimeout with #<TCPSocket:(closed)>): 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:217:in `rbuf_fill' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:191:in `readuntil' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/protocol.rb:201:in `readline' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http/response.rb:42:in `read_status_line' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http/response.rb:31:in `read_new' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1528:in `block in transport_request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1519:in `catch' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1519:in `transport_request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:1492:in `request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/tracer.rb:34:in `instrument' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/scout_apm-4.1.2/lib/scout_apm/tracer.rb:44:in `instrument' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/sentry-ruby-core-4.8.1/lib/sentry/net/http.rb:40:in `request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/ruby-2.7.2/lib/ruby/2.7.0/net/http.rb:933:in `start' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:122:in `perform_request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /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' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/adapter.rb:50:in `connection' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:64:in `call' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/request/url_encoded.rb:25:in `call' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/request/multipart.rb:30:in `call' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/rack_builder.rb:154:in `build_response' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/connection.rb:516:in `run_request' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/faraday-1.8.0/lib/faraday/connection.rb:281:in `put' 
Feb 23 20:24:42 Surventrix2.0 app/worker.1 /app/vendor/bundle/ruby/2.7.0/gems/aspose_words_cloud-21.12.0/lib/aspose_words_cloud/api_client.rb:156:in `block in build_request' 

@nikhilgoyal2205

We are sorry for the inconvenience. It looks like the requests are not reached out to our server, so missing in the logs. However, we can comment exactly after replicating the issue at our end. Can you please share your sample input document that caused the problem? It will help us to investigate the issue.

@tilal.ahmad I literally showed you the error trace how did that not reach, it must be a traffic issue at your end. The same request worked next time. This happened multiple times yesterday

@nikhilgoyal2205

We have logged a ticket WORDSCLOUD-1934 to investigate the server logs and will share our findings with you as soon as possible.

@tilal.ahmad just FYI, it can be either template rendering or converting word to PDF.
Below is the code block where these steps take place.

def merge
    mail_merge_request = AsposeWordsCloud::ExecuteMailMergeOnlineRequest.new(template: load_file(@record), data: Field.tape_fields(@record))
    output_doc = @words_api.execute_mail_merge_online(mail_merge_request)
    convert_request = AsposeWordsCloud::ConvertDocumentRequest.new(document: File.open(output_doc), format: 'pdf')
    @words_api.convert_document(convert_request)
  end

@nikhilgoyal2205

Thanks for your sample code. We will appreciate it if you please also share your sample code, how you are setting timeout property.

@tilal.ahmad

require 'aspose_words_cloud'

AsposeWordsCloud.configure do |config|
  config.client_data['ClientId'] = Rails.application.credentials.dig(:aspose, :client_id)
  config.client_data['ClientSecret'] = Rails.application.credentials.dig(:aspose, :client_secret)
  config.timeout = 120
end

@nikhilgoyal2205
Thanks for your feedback. We will share our findings with you as soon as we conclude the investigation.

@tilal.ahmad is there any update to this. We have had random timeouts every other day

@nikhilgoyal2205

Though we have made some changes to fine-tune our server performance but still working on the issue. We will update you soon. Thanks for your patience and cooperation.

@nikhilgoyal2205

We will appreciate it if you please share the updated logs. As we did not notice any failure in Aspose.Words Cloud Server since 2nd March 2022.

@tilal.ahmad I was on vacation. FYI, we haven’t had timeouts after 3rd of March I believe but I would like to take some more time to revert back with more data if needed

1 Like