Prawn::Document.text hangs erratically

24 views
Skip to first unread message

Reiner Dieden

unread,
Jun 4, 2017, 6:26:40 PM6/4/17
to Prawn
Dear all,

I'm using prawn in a rails-app for generating very simple PDF's from ascii-text files generated elsewhere.  The problem I'm facing is that the script hangs unpredictably from time to time.
The goal is to render characters aligned, hence I want to use courier as a font and am replacing multiple spaces by single nbsps. (Without this replacement, the issue doesn't occur)

From a failling input file, I was able to isolate a part (@results) and to put the following bit of code together to reproduce the problem.

I used a loop to determine the minimal string that cause the script to hang (it occurs when cnt==120).
If I inject that failing string (failText) directly, no hang occurs - unless whitespace is substituted (failTextcorr), but then it hangs at an earlier moment (cnt==18)

Am I grossly misunstanding something here or is this a bug?  I found something similar here.

I'd appreciate if anyone could help me with this.

#!ruby -w
require 'prawn'

Prawn::Font::AFM.hide_m17n_warning = true

@results="__run of 2017-05-31 19:23:28 +0200 version e018c5b932dde9a45b63c8344589f2e9fe29175b data_file: /var/folders/mr/0pl2p46j28s5j13r7vqgyhwh0000gn/T/RackMultipart20170531-55394-ithydk.txt"

failText
="__run of 2017-05-31 19:23:28 +0200 version e018c5b932dde9a45b63c8344589f2e9fe29175b data_file: /var/folders/mr/0pl2p46j2"

text
=@results.gsub(/\s+/, Prawn::Text::NBSP)

failTextcorr
=failText.gsub(/\s+/, Prawn::Text::NBSP)
text2
=text.split ''
myText
=''
cnt
=0

Prawn::Document.generate('out.pdf') do
  text2
.each do |ch|
    cnt
+=1
    myText
+=ch
    puts
"#{cnt} #{myText} #{myText==failText} #{myText==failTextcorr}"
    text myText        
# fails at cnt==120 (when myText == failTextcorr)
   
#text failText      # doesn't fail
   
#text failTextcorr  # fails at cnt==18
 
end
 
#text failTextcorr    # doesn't fail
 
#render_file "out.pdf"
end




Alexander Mankuta

unread,
Jun 5, 2017, 4:48:32 AM6/5/17
to Prawn
Hi,

I tried your script as is on MRI 2.4.0 with both the latest stable Prawn and master. I can not reproduce the issue you describe. Does it happen every time? What version Ruby/Prawn/OS do you run?

You also mentioned that you use Courier font but the example doesn't use it.

You also didn't tell what the failure for the example script is. Is there any output? In case of a hang up what does the script do? Does it consume CPU? Does it eat up all your memory? Does it just sit doing nothing?

I'm also not sure how the linked thread is related to your issue.

--
Regards,
Alex

Reiner Dieden

unread,
Jun 5, 2017, 10:50:36 AM6/5/17
to Prawn
Hi,

Sorry, I should obviously have mentioned the versions: I'm running the script with ruby 2.2.1, prawn (2.1.0), pdf-core (~> 0.6.1), ttfunk (~> 1.4.0) under OS X 10.10.5.  The rails app where the issue originally turned up runs with  rails 4.2.3 under Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-66-generic x86_64).
The problem is reproducible for a particular input file, but doesn't occur with all of them.
There's absolutely no output: ruby is consuming cpu and memory usage is rising slowly, but surely, rising (from 30MB at start to 600MB after a couple of minutes).

The linked thread caught my eye because of similar circumstances: the rails server becomes unresponsive and must be restarted, the runaway ruby process must be killed and nonbreaking spaces are involved.
--
Regards,

Reiner
Reply all
Reply to author
Forward
0 new messages