a way to restart comet after network partition

Skip to first unread message


Dec 4, 2020, 3:36:53 PM12/4/20
to Nitrogen Project / The Nitrogen Web Framework for Erlang

Hello Nitroboys (or Nitrodevs, or Nitrogeneers, or Nitrogenes...). Im having problems with comets.

I want my comets to restart after network reconnection succeeds.

As far as I know this should work:

  reconnect_actions=#event{postback={reconnect, CometFunction}}})
event({reconnect, Fun}) ->
   wf:wire(#comet{function=Fun, reconnect_actions=...})

Maybe Im missing something because thats what I have in my page and Im trying to reproduce the case by accessing the server from a VM with Windows. I tried pausing the VM for 5 minutes or by turning off the virtual network card, but after I reconnect the VM the event doesnt get triggered. 

The js console says:
> Websockets disabled or disconnected
> Websockets Enabled
(the red banner on top of the page seems to work as intented, it shows up, then dissapears)

but I get no {reconnect, ...}

Maybe im too stressed but I swear I got the event triggered one time, and I begun to refactorize the code until I can no longer reproduce it. I swear It worked 1 or 2 times, but now it doesnt. I didnt have the event/1 function implemented so I got a undef error, which was totally fine..., the reconnection path was taking place...

What am I doing wrong?

By doing a simple wf:comet(fun() -> ... end) I have monitored the {ok, Pid} process,
and it actually goes down just a few seconds after I do a network partition in a systematic way.

This is so much important for an SPA, it is the last stepping stone in my quest to get confident enough with Nitrogen to produce superior SPA experiences.

Jesse Gumm

Dec 6, 2020, 12:07:51 PM12/6/20
to nitrogenweb
Hey Franklin,

So somehow, the {reconnect, CometFunction} postback isn't triggering on reconnect.

Here's the trail you can follow to try to figure this out:

The way it's "supposed" to work is as follows:

The reconnect_action, defined in the #comet{} action ends up queuing a "reconnection event" in nitrogen.js.  You can see this here: 

Once that reconnection event is queued, when the system reconnects, it ultimately ends up calling Nitrogen.$enable_websockets: 

This ends up calling the $flush_switchover_comet_action function, which ends up being processed in nitrogen.erl, and triggers the wired call to Nitrogen.$reconnect_system()

That call ends up being handled here:

That $reconnect_system() function loops through the queued reconnection events (in your case the {reconnect, CometFunction} postback).

If you trace along that path, you should be able to figure out at which step along the way the reconnect is failing, and from there, we can try to come to a solution.


You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nitrogenweb/bfe9f00f-3afd-461f-9bc6-99913d0be9bbn%40googlegroups.com.

Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm
Reply all
Reply to author
0 new messages