Skip to content

Commit afd5f68

Browse files
committed
- Fixed a bug with a potentially lingering timer if the socket was closed remotely
- Various logging tweaks
1 parent 81e5dc0 commit afd5f68

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

src/main/java/org/digitalmediaserver/cast/Channel.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ public boolean connect() throws IOException, NoSuchAlgorithmException, KeyManage
400400
throw new CastException("Authentication failed: " + authResponse.getError().getErrorType().toString());
401401
}
402402

403+
// Make extra sure we're not losing the reference to a live thread
404+
if (inputHandler != null) {
405+
inputHandler.stopProcessing();
406+
}
403407
// Start input handler
404408
inputHandler = new InputHandler(socket.getInputStream());
405409
inputHandler.start();
@@ -412,6 +416,10 @@ public boolean connect() throws IOException, NoSuchAlgorithmException, KeyManage
412416
PLATFORM_RECEIVER_ID
413417
);
414418

419+
// Make extra sure that we're not losing the reference to a live timer
420+
if (pingTimer != null) {
421+
pingTimer.cancel();
422+
}
415423
// Start regular pinging
416424
PingTask pingTask = new PingTask();
417425
pingTimer = new Timer(remoteName + " PING timer");
@@ -441,7 +449,7 @@ public void close() throws IOException {
441449
Set<Session> closedSessions = null;
442450
synchronized (sessionsLock) {
443451
synchronized (socketLock) {
444-
if (socket == null || socket.isClosed() || !socket.isConnected()) {
452+
if (socket == null) {
445453
// Already closed
446454
return;
447455
}
@@ -2563,7 +2571,7 @@ public void run() {
25632571
} else {
25642572
sb.append(", binary payload: ").append(((ImmutableBinaryCastMessage) message).getPayload());
25652573
}
2566-
LOGGER.debug(CAST_API_MARKER, "Triggering (potentially partial) message: {}", sb.toString());
2574+
LOGGER.debug(CAST_API_MARKER, "Discarding (potentially partial) message: {}", sb.toString());
25672575
}
25682576
LOGGER.trace(CAST_API_MARKER, "", e);
25692577
running = false;
@@ -2575,12 +2583,13 @@ public void run() {
25752583
return;
25762584
}
25772585
}
2578-
LOGGER.trace(
2586+
LOGGER.debug(
25792587
CAST_API_MARKER,
25802588
"Exception while shutting down {} InputHandler: {}",
25812589
remoteName,
25822590
e.getMessage()
25832591
);
2592+
LOGGER.trace(CAST_API_MARKER, "", e);
25842593
}
25852594
try {
25862595
close();
@@ -2680,18 +2689,24 @@ protected void processStringMessage(@Nonnull ImmutableStringCastMessage message,
26802689
}
26812690
}
26822691
} else {
2683-
StandardResponse response;
2692+
StandardResponse response = null;
26842693
if (!isBlank(responseType)) {
26852694
try {
26862695
response = jsonMapper.treeToValue(parsedMessage, StandardResponse.class);
26872696
} catch (JsonMappingException e) {
2688-
response = null;
2697+
LOGGER.warn(
2698+
CAST_API_MARKER,
2699+
"Failed to parse \"{}\" message from {} with content: {}: {}",
2700+
responseType,
2701+
remoteName,
2702+
parsedMessage,
2703+
e.getMessage()
2704+
);
2705+
LOGGER.trace("", e);
26892706
}
2690-
} else {
2691-
response = null;
26922707
}
26932708

2694-
if (response instanceof StandardResponse && response.getEventType() != null) {
2709+
if (response != null && response.getEventType() != null) {
26952710
ReceiverStatus receiverStatus;
26962711
if (
26972712
response instanceof ReceiverStatusResponse &&

0 commit comments

Comments
 (0)