Skip to content

Commit 4917658

Browse files
committed
WebSocket fixes for NPE and clean up
1 parent 47d62bf commit 4917658

File tree

12 files changed

+72
-45
lines changed

12 files changed

+72
-45
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.0</version>
6+
<version>1.3.1</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-client</artifactId>

client/src/main/java/org/red5/client/Red5Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Red5Client {
1818
/**
1919
* Current server version with revision
2020
*/
21-
public static final String VERSION = "Red5 Client 1.3.0";
21+
public static final String VERSION = "Red5 Client 1.3.1";
2222

2323
/**
2424
* Create a new Red5Client object using the connection local to the current thread A bit of magic that lets you access the red5 scope

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.0</version>
6+
<version>1.3.1</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-server-common</artifactId>

common/src/main/java/org/red5/server/api/Red5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public final class Red5 {
5555
/**
5656
* Server version with revision
5757
*/
58-
public static final String VERSION = "Red5 Server 1.3.0";
58+
public static final String VERSION = "Red5 Server 1.3.1";
5959

6060
/**
6161
* Server version for fmsVer requests
6262
*/
63-
public static final String FMS_VERSION = "RED5/1,3,0,0";
63+
public static final String FMS_VERSION = "RED5/1,3,1,0";
6464

6565
/**
6666
* Server capabilities

common/src/main/java/org/red5/server/scheduling/JDKSchedulingServiceJob.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public void run() {
5454
IScheduledJob job = null;
5555
try {
5656
job = (IScheduledJob) jobDataMap.get(ISchedulingService.SCHEDULED_JOB);
57-
job.execute(service);
57+
if (job != null) {
58+
job.execute(service);
59+
}
5860
} catch (Throwable e) {
59-
if (job == null) {
60-
log.warn("Job not found");
61-
} else {
61+
if (job != null) {
6262
log.warn("Job {} execution failed", job.toString(), e);
6363
}
6464
} finally {

io/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.0</version>
6+
<version>1.3.1</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-io</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<name>Red5</name>
2424
<description>The Red5 server</description>
2525
<groupId>org.red5</groupId>
26-
<version>1.3.0</version>
26+
<version>1.3.1</version>
2727
<url>https://github.com/Red5/red5-server</url>
2828
<inceptionYear>2005</inceptionYear>
2929
<organization>

server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.0</version>
6+
<version>1.3.1</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-server</artifactId>

server/src/main/java/org/red5/net/websocket/WebSocketConnection.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,21 @@ public void close() {
329329
CloseReason reason = new CloseReason(CloseCodes.GOING_AWAY, "");
330330
// close the socket, don't wait for the browser to respond or we could hang
331331
session.onClose(reason);
332-
// clean up our props
333-
attributes.clear();
332+
}
333+
// clean up our props
334+
attributes.clear();
335+
if (querystringParameters != null) {
334336
querystringParameters.clear();
335337
querystringParameters = null;
338+
}
339+
if (extensions != null) {
336340
extensions.clear();
337341
extensions = null;
338-
if (headers != null) {
339-
headers = null;
340-
}
342+
}
343+
if (headers != null) {
344+
headers = null;
345+
}
346+
if (scope.get() != null) {
341347
// disconnect from scope
342348
scope.get().removeConnection(this);
343349
// clear weak refs
@@ -419,7 +425,11 @@ public void setOrigin(String origin) {
419425
* @return true if secure and false if unsecure or unconnected
420426
*/
421427
public boolean isSecure() {
422-
return (wsSession != null && wsSession.get().isOpen()) ? wsSession.get().isSecure() : false;
428+
Optional<WsSession> opt = Optional.ofNullable(wsSession.get());
429+
if (opt.isPresent()) {
430+
return (opt.get().isOpen() ? opt.get().isSecure() : false);
431+
}
432+
return false;
423433
}
424434

425435
public String getPath() {

server/src/main/java/org/red5/net/websocket/WebSocketScopeManager.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,34 @@ public boolean addWebSocketScope(WebSocketScope webSocketScope) {
159159
scopes.forEach((sName, wsScope) -> {
160160
log.trace("start pinging scope: {}", sName);
161161
wsScope.getConns().forEach(wsConn -> {
162-
// ping connected websocket
163-
if (wsConn.isConnected()) {
164-
log.debug("pinging ws: {} on scope: {}", wsConn.getWsSessionId(), sName);
165-
try {
166-
wsConn.sendPing(PING_BYTES);
167-
} catch (Exception e) {
168-
log.debug("Exception pinging connection: {} connection will be closed", wsConn.getSessionId(), e);
169-
// if the ping fails, consider them gone
170-
wsConn.close();
162+
try {
163+
// ping connected websocket
164+
if (wsConn.isConnected()) {
165+
log.debug("pinging ws: {} on scope: {}", wsConn.getWsSessionId(), sName);
166+
try {
167+
wsConn.sendPing(PING_BYTES);
168+
} catch (Exception e) {
169+
log.debug("Exception pinging connection: {} connection will be closed", wsConn.getSessionId(), e);
170+
// if the connection isn't connected, remove them
171+
wsScope.removeConnection(wsConn);
172+
// if the ping fails, consider them gone
173+
wsConn.close();
174+
}
175+
} else {
176+
log.debug("Removing unconnected connection: {} during ping loop", wsConn.getSessionId());
177+
// if the connection isn't connected, remove them
178+
wsScope.removeConnection(wsConn);
171179
}
172-
} else {
173-
log.debug("Removing unconnected connection: {} during ping loop", wsConn.getSessionId());
174-
// if the connection isn't connected, remove them
175-
wsScope.removeConnection(wsConn);
180+
} catch (Exception e) {
181+
log.warn("Exception in WS pinger", e);
176182
}
177183
});
178184
log.trace("finished pinging scope: {}", sName);
179185
});
180186
// sleep for interval
181187
try {
182188
Thread.sleep(websocketPingInterval);
183-
} catch (InterruptedException e1) {
189+
} catch (InterruptedException e) {
184190
}
185191
} while (!scopes.isEmpty());
186192
// reset ping future

0 commit comments

Comments
 (0)