igrigorik / em-websocket

EventMachine based WebSocket server

Home Page:http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with EM-Websocket running in a thread under JRuby

awood opened this issue · comments

I'm working on some code that runs EM-Websocket in a thread. It works fine under MRI but fails under JRuby. I've created a reproducer here with more details in the README but I will give a brief outline here:

I'm using EM-Websocket to implement LiveReload functionality for the Jekyll static site generator. The goal is for users to run jekyll serve --livereload and Jekyll will refresh a connected browser as it regenerates pages based on changes the user makes to the underlying files, in effect giving the user a real-time preview of how their changes will appear.

To accomplish this, I start an EventMachine reactor in a separate thread that is responsible for sending the LiveReload messages over the websockets connection. When Jekyll regenerates a file, I've inserted a hook that prompts the reactor to send a reload message to the browser.

Under JRuby, the reload messages never actually seem to get sent. I've looked at packet captures (also provided in the reproducer repo referenced earlier) under both the MRI and JRuby and the packets with the reload message never actually hit the wire under JRuby (although the initial LiveReload handshake does get made).

This may be a problem with EventMachine itself; I'm not enough of an expert to tell, but I thought I would start by reporting the issue here since my use case is websockets specific.

Any assistance or insight you could provide would be greatly appreciated.

Have you tried instrumenting the code to see if send_data is being called? I have a hunch that there is something in the guts of EventMachine.. or we have some callback exploding & being swallowed.

Yeah, it looks like send_data in connection.rb in EventMachine just invokes EventMachine::send_data @signature, data, size and then... nothing. So this does appear to be a problem in EventMachine itself. Thanks for the suggestion on instrumenting the code.

D'oh. Looks like someone else already hit this issue! Sorry for the spurious issue report!