You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Daniel Stoch (Jira)" <ji...@apache.org> on 2023/03/23 14:15:00 UTC

[jira] [Comment Edited] (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=17704163#comment-17704163 ] 

Daniel Stoch edited comment on WICKET-7034 at 3/23/23 2:14 PM:
---------------------------------------------------------------

[~reiern70] 

A server generated ping is also some solution. But it requires more resources (some server thread?) and generates additional network traffic. I don't know is it really necessary when we can perform such reconnection initiated by a client browser if needed?


was (Author: interface):
[~reiern70] 

A server generated ping is also some solution. But it requires more resources and generates additional network traffic. I don't know is it really necessary when we can perform such reconnection initiated by a client browser if needed?

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