Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Net:HTTP / HTTParty calls interrupt Watir-Webdriver script / Net::ReadTimeout error

I've set up a Watir-Webdriver script which I want to report to a remote service:

  puts "Starting..."

  b = Watir::Browser.new :ie
  puts "Started browser"

  puts "Setting status as non-idle"

  request = Net::HTTP::Post.new()
  url = URI(HOME + '/update_status')
  request.body = JSON.generate({ scrapeId: SCRAPE_ID, status: 'working' })
  # This step freezes processing
  Net::HTTP.start(url.host, url.port) {|http| http.request(request)}

  puts "This step never happens"

At the same time, node.js/express watir is pinging to has the following endpoint:

app.post('/update_status', function(req, res) {
  redis.hset(req.body.scrapeId, 'status', req.body.status);
  if (req.body.status === 'finished') {
    redis.expire(req.body.scrapeId, SIX_HOURS);
  }
  res.send('response from post /update_status');
});

Question: Why is Net::HTTP timing out when hitting /update_status? Interestingly, if server returns 404 (endpoint doesn't exist), Watir script continues normally.

Net::ReadTimeout is obviously the culrpit, but why?

like image 275
dsp_099 Avatar asked Oct 30 '22 11:10

dsp_099


1 Answers

"Assumption is the mother of all problems" - paraphrasing some very smart guy or gal.

The answer was as simple as it was silly - I added a node.js middleware omitting the next(); in it. Nothing wrong with the script, as it turns out - I was looking in the wrong place and didn't have a test for it. Whoops.

like image 160
dsp_099 Avatar answered Nov 15 '22 05:11

dsp_099