You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Tzvetanov Grigorov (Jira)" <ji...@apache.org> on 2023/03/21 19:45:00 UTC

[jira] [Commented] (WICKET-7034) WebSocket.Closed event not fired when error occurred

    [ https://issues.apache.org/jira/browse/WICKET-7034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703347#comment-17703347 ] 

Martin Tzvetanov Grigorov commented on WICKET-7034:
---------------------------------------------------

Please send a PR!

> 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
>
> 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)