Daniel Stoch created WICKET-7034:
------------------------------------
Summary: WebSocket.Closed event not fired when error occurred
Key: WICKET-7034
URL: https://issues.apache.org/jira/browse/WICKET-7034
Project: Wicket
Issue Type: Bug
Components: wicket-native-websocket
Affects Versions: 9.12.0, 8.14.0, 7.18.0, 6.29.0
Reporter: Daniel Stoch
Assignee: Martin Tzvetanov Grigorov
In wicket-websocket-jquery.js there are self.ws.onclose, self.ws.onerror event
handlers which publish Closed/Error event to subscribers. A problem may occur
when websocket connection is closed after error, because in onerror hander a
self.ws is cleared (null), so the subsequent call to onclose do not fire
topics.Closed event:
{code}
self.ws.onclose = function (evt) {
if (self.ws) {
self.ws.close();
self.ws = null;
Wicket.Event.publish(topics.Closed, evt);
}
};
self.ws.onerror = function (evt) {
if (self.ws) {
self.ws.close();
self.ws = null;
Wicket.Event.publish(topics.Error, evt);
}
};
{code}
Maybe we should publish this events even if self.ws is null as follows?
{code}
self.ws.onclose = function (evt) {
if (self.ws) {
self.ws.close();
self.ws = null;
}
Wicket.Event.publish(topics.Closed, evt);
};
self.ws.onerror = function (evt) {
if (self.ws) {
self.ws.close();
self.ws = null;
}
Wicket.Event.publish(topics.Error, evt);
};
{code}
I have tested this using some reverse proxy configuration with 20s timeout for
request.
In Firefox and Chrome after timeout onclose event is fired with code 1006.
But in Safari onerror is fired first and then onclose event (also with code
1006) - but in this browser topics.Closed is not published because self.ws is
"nullified" in onerror event handler.
PS. I am trying to implement websocket auto reconnect in such scenario using
this event handler. It looks like it should work but I am not sure is it the
best solution ;).
{code}
Wicket.Event.subscribe('/websocket/closed', function(jqEvent, attributes) {
if (attributes.code == 1006) {
Wicket.WebSocket.close();
Wicket.WebSocket.createDefaultConnection();
}
});
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)