Hi all,
I'd like my Java CometD client to reconnect after some kind of network outage and I've some questions about that.
I'm using CometD-2.6.0, the Java client and Web Sockets (but Long Poll expected to work, too).
There is authentication with a `SecurityPolicy` that verifies user's identity at handshake time and it works well.
I support an optional two-factor authentication. At CometD level, it relies on handshake message customization (as the documentation kindly explains). Two-factor authentication makes things special, because a reconnection after session loss must pop a dialog up, asking for a new code.
I'd like to simulate network outages on my laptop. First I did shut down the loopback interface (`sudo ifconfig lo0 down`). It's not completely unrealistic (seems that I get the same errors with a remote server, when stopping Wi-Fi) but I felt like missing more frequent errors, and this kind of low-level hacking doesn't fit in a JUnit test suite.
I decided to simulate the outage using DonsProxy (
http://donsproxy.moneybender.com ). DonsProxy looks good because it's a full Java proxy. I know that network problem simulators aren't as vicious as platform-dependant network stacks but this one might give a good start. The network outages I produce interactively:
- Stop the proxy for one second, send a CometD message, then restart it.
- Stop the proxy for one minute, then restart it.
- Close the connection for one second, send a CometD message, then reopen it.
- Close the connection for one minute, then reopen it.
I'm using CometD default options (as far as I know the timeout is 30 s).
CometD doesn't recover after a one-minute outage nor after a proxy interruption.
After closing the connection from DonsProxy and sending a CometD message, I get `META_CONNECT` notifications with `successful->false`. When I reopen the connection I get a lot of `META_CONNECT' notifications with `successful->true` (about one every 10 s) but any further attempt to send messages to the server fails. Of course the debugger may break the timings.
Before hacking stupid things here I'm asking: How to get notified that network is available again, //but// the session has expired? With such a hook I could disconnect and run a full reconnection,with or without two-factor authentication.
By the way, does my proxy-based network error simulation make sense? If not, how to automate deterministic network outages in full Java?
Thanks for this great product, and all the discussion on this list.
c.