[ https://issues.apache.org/jira/browse/WICKET-7034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703595#comment-17703595 ]
ASF GitHub Bot commented on WICKET-7034: ---------------------------------------- martin-g commented on PR #562: URL: https://github.com/apache/wicket/pull/562#issuecomment-1479309848 Oops! I pushed it to a wrong branch! > 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)