[ https://issues.apache.org/jira/browse/WICKET-7034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17704861#comment-17704861 ]
ASF subversion and git services commented on WICKET-7034: --------------------------------------------------------- Commit 25d4f5016d2218028f1a997fb1647091088fefd5 in wicket's branch refs/heads/fileCountMax-9.x from Daniel Stoch [ https://gitbox.apache.org/repos/asf?p=wicket.git;h=25d4f5016d ] WICKET-7034: Publish WebSocket events even if connection was already closed (#562) Co-authored-by: Daniel Stoch <daniel.st...@comarch.com> > 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: 6.29.0, 7.18.0, 8.14.0, 9.12.0 > Reporter: Daniel Stoch > Assignee: Martin Tzvetanov Grigorov > Priority: Major > Fix For: 10.0.0, 9.13.0 > > > 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)