newshour/map_center — pull request #15 by jugglinmike (2012-09-10 22:43:22+00:00)
Title: Prevent race condition in broadcast logic

Broadcasting clients are already able to ignore messages they have just
sent by comparing the new state to their current state. If the two
match, they can safely ignore the message.

This does not protect against the case where a broadcaster sends two
messages in quick successiion. Under this condition, the broadcaster
may already be in the second state when receiving the message describing
the first state change. This will trigger an infinite loop while the
broadcaster constantly alternates between the two states.

This change prevents the server from sending messages back to the
originating broadcaster. Socket.io provides a simpler API for this
(through socket.broadcast), but the use of namespaces precludes this
approach. The change here uses the public API to accomplish similar
functionality.