This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git

commit 194f3b217fee3e7f25c1945717069a18a2bc3321
Author: Maxim Solodovnik <solomax...@gmail.com>
AuthorDate: Sun May 3 15:14:01 2020 +0700

    [OPENMEETINGS-2301] code is improved a bit (original issue still 
reproducible)
---
 .../openmeetings/core/util/WebSocketHelper.java    | 32 ++++++++++++++++------
 .../openmeetings/web/room/sidebar/RoomSidebar.java |  4 +--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git 
a/openmeetings-core/src/main/java/org/apache/openmeetings/core/util/WebSocketHelper.java
 
b/openmeetings-core/src/main/java/org/apache/openmeetings/core/util/WebSocketHelper.java
index 1584b36..30d9750 100644
--- 
a/openmeetings-core/src/main/java/org/apache/openmeetings/core/util/WebSocketHelper.java
+++ 
b/openmeetings-core/src/main/java/org/apache/openmeetings/core/util/WebSocketHelper.java
@@ -55,31 +55,45 @@ import com.github.openjson.JSONObject;
 public class WebSocketHelper {
        private static final Logger log = 
LoggerFactory.getLogger(WebSocketHelper.class);
 
-       public static void sendClient(final IWsClient inC, byte[] b) {
-               if (inC != null) {
-                       sendClient(inC, c -> {
+       public static void sendClient(final IWsClient omClient, byte[] b) {
+               if (omClient != null) {
+                       sendClient(omClient, c -> {
                                try {
                                        c.sendMessage(b, 0, b.length);
-                               } catch (IOException e) {
+                               } catch (Throwable e) {
                                        log.error("Error while sending binary 
message to client", e);
                                }
+                               checkClosed(c, omClient);
                        });
                }
        }
 
-       public static void sendClient(final IWsClient inC, JSONObject msg) {
-               log.trace("Sending WebSocket message to Client: {} -> {}", inC, 
msg);
-               if (inC != null) {
-                       sendClient(inC, c -> {
+       public static void sendClient(final IWsClient omClient, JSONObject msg) 
{
+               log.trace("Sending WebSocket message to Client: {} -> {}", 
omClient, msg);
+               if (omClient != null) {
+                       sendClient(omClient, c -> {
                                try {
                                        c.sendMessage(msg.toString());
-                               } catch (IOException e) {
+                               } catch (Throwable e) {
                                        log.error("Error while sending message 
to client", e);
                                }
+                               checkClosed(c, omClient);
                        });
                }
        }
 
+       private static void checkClosed(IWebSocketConnection c, final IWsClient 
omClient) {
+               if (c.isOpen()) {
+                       return;
+               }
+               log.error("!!!!WS connection is closed in sendMessage");
+               WebSocketSettings settings = 
WebSocketSettings.Holder.get((Application)getApp());
+               IWebSocketConnectionRegistry reg = 
settings.getConnectionRegistry();
+               reg.removeConnection(c.getApplication(), c.getSessionId(), 
c.getKey());
+               if (omClient instanceof Client) {
+                       
getApp().getBean(IClientManager.class).exit((Client)omClient);
+               }
+       }
        public static IApplication getApp() {
                return 
(IApplication)Application.get(getWicketApplicationName());
        }
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/RoomSidebar.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/RoomSidebar.java
index f328010..76bb8f1 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/RoomSidebar.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/room/sidebar/RoomSidebar.java
@@ -81,9 +81,9 @@ public class RoomSidebar extends Panel {
                @Override
                protected void respond(AjaxRequestTarget target) {
                        StringValue s = 
getRequest().getRequestParameters().getParameterValue(PARAM_SETTINGS);
-                       if (!s.isEmpty()) {
+                       Client c = room.getClient();
+                       if (!s.isEmpty() && c != null) {
                                ExtendedClientProperties cp = 
WebSession.get().getExtendedProperties();
-                               Client c = room.getClient();
                                cp.setSettings(new 
JSONObject(s.toString())).update(c);
                                if (!avInited) {
                                        avInited = true;

Reply via email to