Is Ruby on Windows failing when dealing with IPv6?

Posted at 16:10 on Monday, 12 July 2010 — with 1 comment.

RUBY Today, I ran across a potentially show-stopping bug — or perhaps non-feature — in Ruby for Windows and it seems to be (although I don’t believe it) down to Ruby’s inability to handle IPv6.

I presented a question on StackOverflow about it, but thought I’d mirror it here just in case anyone has any ideas. So, without further ado:

So I’ve got a tool that I built in Ruby that uses net/http to make some requests to an external REST service. I built and unit tested this tool using Windows 7 and it worked absolutely fine.

Now, since this tool is meant to be run periodically on one of our servers (running Windows Server 2008 R2), I deployed it there and suddenly it’s failing with the following exception:

SocketError: getaddrinfo: The storage control blocks were destroyed.
  C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in `initialize'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in `open'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in `connect'
  C:/Ruby187/lib/ruby/1.8/timeout.rb:53:in `timeout'
  C:/Ruby187/lib/ruby/1.8/timeout.rb:93:in `timeout'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:560:in `connect'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:553:in `do_start'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:542:in `start'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:1035:in `request'
  C:/Ruby187/lib/ruby/1.8/net/http.rb:772:in `get'
    ...

A bit of Googling reveals that this may be an issue with Ruby failing when dealing with IPv6 on a Windows machine. However: it works fine on this Windows 7 machine which has the full IPv6 stack enabled, is connected to the same network and even has the exact same installation of Ruby as the 2K8 server that fails with that error message.

The following is the simplest test case that fails (errors out with the above exception) on Windows Server 2008 but passes on Windows 7:

require "test/unit"
require "net/http"

class IPV6OnWindowsTest < Test::Unit::TestCase

  def test_ipv6_connection
    http = Net::HTTP.new('w3.org', 80)
    response, result = http.get("/", nil)
    assert_not_nil result
  end

end

Remember, using identical Ruby 1.8.7 installations — also occurs with 1.8.6 and 1.9.1, by the way.

Is there anyone out there that can suggest what I might be doing wrong here?

Since these two machines share a lot of properties yet one passes and one fails, I’m finding it hard to believe the conventional wisdom which attributes this to Ruby’s inability to handle IPv6 on Windows.

Thanks in advance!

Tagged as: windows, ruby, ipv6, error, bug

The beauty of the delayed, accumulative task

Posted at 10:07 on Friday, 09 July 2010

TECHNOLOGY For a while now, my much-beloved RememberTheMilk have adopted a classic user-interface detail, the genius of which I’m sure has been overlooked by many. They are certainly not the first — nor will they be the last — to do apply this, so I guess this is more of a celebration of user experience innovation rather than of RTM themselves, but their app does provide a perfect example that the user is explicitly made aware of.

The element I speak of is their process of synchronisation between your mobile client and their servers. When using a mobile device, you’re likely going to be connected to the web via a cellular connection (3G, EDGE or GPRS if you’re that unlucky) and thus your bandwidth is going to be severely limited compared to the fibre line connected to your home. You’ll be limited by both a by-the-second technical transfer rate limitation and maybe even an artificial monthly quota imposed by your carrier.

With a task management app like RTM, the frequency at which you sync between the mobile and your master set of data is going to be fairly high and as we all know — HTTP requests are expensive. It’s good practice to make as little of these requests as possible (a rule that is understandably disobeyed on the desktop where a reliable, snappy connection enables things like AJAX feasible). You also have to give your user a very ‘connected’ experience and ensure your mobile app mirrors the master data as closely as possible. Ahh, the good old performance/usability concession.

RTM Sync Flow

In steps the concept of the delayed, accumulative task. In the same way a delivery company will not deliver packages to your home one-by-one as soon as the shipment is consigned, but rather spool the deliveries received over a certain time period before sending them out as a set, your RememberTheMilk app will, upon seeing an alteration to your data, wait for 3 seconds before notifying their servers of the change. Any other data changes that occur during this 3 second delay will also get noticed by the app and will be sent, in a batch, along with the first change that triggered it.

A fantastic way to reduce the frequency of naturally very slow and bulky HTTP requests over what could be (or will be if you’re on an iPhone) a very spotty data connection where network utilisation should be kept at a minimum — a good rule to follow universally with software development, but all the more important on the mobile. The complexities of enabling data access at multiple endpoints (and concurrency issues in general) are still there, but at least it’s not taxing the device’s potentially limited connectivity.

However, this certainly isn’t a silver bullet. The 3 second delay in accuracy between server and client is not going to cause any out-of-date information inconveniences, but waiting for the sync operation to happen can be a problem. Until iOS 4, iPhone users of the RTM app would literally have to sit and wait for this 3 second delay to finish and the sync process to complete before moving away from the application to do other things (or perhaps to complete the task they just added — those 3 seconds can aggregate to a noticeable productivity sink). This isn’t much of a problem now with the new background task API but a method of interrupting the 3 second delay and forcing an immediate synchronisation I’m sure would be welcomed anywhere this technique is used.

So, in closing, I would like to issue the biggest of big-ups to all the awesome UX designers out there. I hope to someday join your ranks.

Tagged as: mobile, web, rtm, design, user, experience, software

Ruby Game of Life in WPF

Posted at 11:28 on Thursday, 08 July 2010

RUBY A new Ruby Challenge for Newbies has been issued over at RubyLearning by Elise Huard — whom I had the pleasure of hearing talk about evaluating the quality of Rails applications at the Scottish Ruby Conference earlier this year. This challenge, called The Game of Life involves implementing John Conway’s famous Game of Life automaton in Ruby. To explain what it is, let’s quote the Wikipedia article:

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, live or dead. Every cell interacts with its eight neighbours, which are the cells that are directly horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with more than three live neighbours dies, as if by overcrowding.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths happen simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the one before). The rules continue to be applied repeatedly to create further generations.

So, of course, I started typing. It is up to the entrant to decide whether they are going to produce a torus-model (where ‘neighbour’ cells for those on the edge of the board wrap around to the other side of the board) or a box-model (whereby edge cells have no neighbours on those sides). I opted for the former. As I was working on this during a lunchbreak at work, I had no access to a UNIX-based machine on which to run the ncurses simulation packaged with the challenge. So, like any programmer worth his salt, I decided to (after spending an hour or two creating an actual working solution, and unit testing the hell out of it) create a visualisation using WPF — written in IronRuby, so it’s still compliant with the challenge!

All my code for this is available at my fork of the challenge on GitHub, but here’s the important part; the WPF code. Isn’t IronRuby awesome?

require 'WindowsBase'
require 'PresentationFramework'
require 'PresentationCore'
require 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

class GameOfLifeSimulation
  include System::Windows::Controls
  include System::Windows::Media
  include System::Windows::Shapes

  def initialize(game, width = 100, height = 100)
    @window = System::Windows::Window.new
    @window.background = Brushes.Black
    @window.width = width
    @window.height = height
    @window.resize_mode = System::Windows::ResizeMode.NoResize
    @window.title = "WPF Game of Life!"
    
    game.simulation = self
    
    update(game)
    app = System::Windows::Application.new
    app.run(@window)
  end

  def update(game)
    @grid = Grid.new
    @grid.mouse_down { game.evolve }
    
    game.size.times do
      @grid.column_definitions.add ColumnDefinition.new
      @grid.row_definitions.add RowDefinition.new
    end
    
    game.state.each_index do |row_index|
      row = game.state[row_index]
      row.each_index do |col_index|
        col = row[col_index]
        
        rect = Rectangle.new
        rect.fill = col.alive? ? Brushes.YellowGreen : Brushes.DarkGreen
        rect.stroke = Brushes.Black
        
        Grid.set_row(rect, row_index)
        Grid.set_column(rect, col_index)
        @grid.children.add(rect)
      end
    end
    
    @window.content = @grid
  end

end

As long as your implementation of the Game of Life follows the rules of the challenge and implements the observer pattern with an update() callback in order to use this simulation (see my solution for an example), this should enable you to visualise your Game of Life challenge solution on Windows.

I do not, by the way, plan on officially submitting this entry to this competition purely because I do not consider myself a Ruby-newbie — although I fully expect lots of other entries from people who have been doing this half as long as I have to produce far superior solutions.

Tagged as: ironruby, ruby, wpf, game of life, challenge

Ross Rubin: The Kin's Seven Deadly Sins

Posted at 09:18 on Tuesday, 06 July 2010

TECHNOLOGY Kin One, Kin TwoA lot of the criticsm of Microsoft’s social-centric mobile phones has been qualified with “although I’m not part of the Kin’s target market…”. Perhaps it is for this same reason that I was wrong to think the Kin phones were going to be popular among their younger audience.

Either way, Ross Rubin over at Engadget has itemised the reasons he can give for Microsoft bowing out of the handset show after a surprisingly short — but expensive — performance.

With the Kin handsets, Microsoft was too eager to get its hands into the pockets of young social networkers for whom the smartphone market had proven elusive. The key paradox of this was that the Kin data plan was the same for that of other smartphones at Verizon, and that continued to shut out those who aspired to mobile digital sharing nirvana.

Read more: Switched On: Kin’s seven deadly sins

Tagged as: microsoft, mobile, handset, kin

Version 2

Posted at 20:51 on Monday, 05 July 2010

UNCLASSIFIED If only I wrote content as frequently…

I kind of impressed myself with how long I lasted without redesigning my blog. Historically, I’ve been very aesthetically restless with any property — online or offline — and would regularly tear down the look of something on a whim.

Yesterday (two years after I started this, my first “serious” foray into blogging), I opened up photoshop, hit the little shuffle button on iTunes, locked my door and just went to town. I prepared sketches using my iPad, arranged colour palettes, even re-calibrated the colour on both my monitors. It’s almost as if I had some kind of process or something.

Five hours later, this happened — and I’m very glad it did. The sparsity of everything makes it more pleasant to read and still maintains the feel of the original. I even got a little bit of french into the tagline because I’m obviously quirky and sophisticated. Anyone who tells you otherwise is a fucking liar.

Tagged as: design, me, blog, trq

Photo of Edd Morgan

Edd Morgan is a software developer, amateur photographer, armchair critic, atheist and lover of all things technology.

Twitter @eddm

My Game Center username is 'eddm'; so all of you can add me and we can play one of the 0 games available for it.

about 8 hours ago

That's my Jam

Bonobo
 - Black Sands

Flickr Faves

Flickr Photo Flickr Photo
Flickr Photo Flickr Photo

Syndication