Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: how to debug localhost not responding with delayed_job / foreman
    primarykey
    data
    text
    <p>I have a task that creates new activerecord records which I have recently moved to a background task using delayed_job and foreman, <a href="https://devcenter.heroku.com/articles/delayed-job" rel="nofollow noreferrer">as recommended by Heroku</a></p> <p>Sometimes this works fine, but sometimes it causes the Rails app in the browser to stop responding.</p> <p>At this point I can see from the database that all the delayed jobs have completed, and that all the new records have been created.</p> <p>However when I kill the processes I get a futher 11,200 lines of terminal output. This mostly consists of the execution by the web process of two methods on the model, both of which involve calls to the database:</p> <pre><code>validate :hit_database_to_see_if_model_exists? before_save :get_rows_from_database_and_perform_calculation </code></pre> <p>There are also a number of INSERT statements which I'm sure have already hit the database because the number of records does not change before/after killing the processes</p> <p>Here is my Procfile:</p> <blockquote> <p>web: bundle exec rails server thin -p $PORT -e $RACK_ENV </p> <p>worker: bundle exec rake jobs:work</p> </blockquote> <p>So it feels like I am getting a 'stack overflow' (woop). Can you shed any light on:</p> <ul> <li>What generally is going on?</li> <li>Where in Rails this 'stack overflow' is taking place </li> <li>Whether these things are actually happening after I hit 'Ctrl + C' or just being printed to the terminal at that point?</li> <li>What might be causing this?</li> <li>How I could debug / fix it?</li> </ul> <p><strong>UPDATE</strong></p> <p>It looks like there are certain tasks that are being assigned to the web process by the background task, but not being executed until the browser is 'prodded.' In some circumstances they all execute, but if there are too many the app falls over. Any idea on what might be causing this?</p> <p><strong>UPDATE</strong></p> <p>I tried running the web and worker processes in two separate windows.</p> <p>In this scenario I have been unable to replicate the problem of the browser hanging, and in each case the worker process completed properly. </p> <p>However I did make the interesting observation that if I don't touch the browser then no output appears in the web window. However if I do touch the browser then thousands of lines of what the worker process is doing at that moment appear in the web window.</p> <p>Is this normal? Does this shed any light on what the problem might be?</p> <p><strong>Update</strong></p> <p>At the bottom of the terminal output after I kill the processes it says "Killed: 9"</p> <blockquote> <p>07:45:21 system | sending SIGKILL to all processes </p> <p>Killed: 9</p> </blockquote> <p>What exactly does this 9 refer to? Is this unusual?</p> <p><strong>Update</strong></p> <p>I am using:</p> <ul> <li>delayed_job 3.0.4 </li> <li>delayed_job_active_record 0.3.3 </li> <li>delayed_job_web 1.1.2 </li> <li>foreman 0.60.2</li> </ul> <p><strong>RESOLUTION</strong></p> <p>Thanks to @Justin's answer below (and <a href="https://stackoverflow.com/questions/8717198/foreman-only-shows-line-with-started-wit-pid-and-nothing-else">this related question</a>). It seems that Ruby buffers stdout by default, and that this buffer was overflowing, causing the app to stop responding. I added <code>$stdout.sync = true</code> at the top of config/environments/development.rb, and the problem appears to have gone away.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload