I’m having trouble keeping a Redis subscriber alive, it keeps dying after a few days (randomly). I suspect the server logs a not too verbose 500 error when it happens:
//access.log
2018-11-0221:12:27UTC comment server ERROR 500 - - - - - 380781.39 - - - - - - - - - - - - - - - - - - - - - - - - -
//error.log
ERROR server comment 2018-11-02 21:12:27 - - - - - 380781.39 - - - - - - - - -
Redis subscriber runs as a separate thread:
this.sessionChecker = new Thread(new SessionChecker(appInstance, this.pool), "subscriberThread");
this.sessionChecker.start();
Perhaps there’s a way to get a better grip on the thread, catch it crashing and print the stack trace and restart it?
Also I suspect the crash lies inside this function because I have logging before and after calling the check() function and I don’t get the after logs.
public void check(String message){
try {
JSONObject obj = new JSONObject(message);
int broadcasterId = obj.getJSONObject("broadcaster").getInt("id");
int userId = obj.getJSONObject("user").getInt("id");
String sessionId = obj.getJSONObject("user").getString("sessionId");
String status = obj.getString("status");
Iterator<IClient> it = app.getClients().iterator();
while (it.hasNext()) {
IClient client = it.next();
List<IMediaStream> playStreams = client.getPlayStreams();
Iterator<IMediaStream> iter = playStreams.iterator();
while (iter.hasNext()) {
IMediaStream stream = (IMediaStream) iter.next();
if (stream.isOpen() && stream.getName().contains(Integer.toString(broadcasterId))){
String ip = stream.getClient().getIp();
String queryStr = stream.getQueryStr();
if (status.equals("peek")){
if (queryStr.contains(sessionId)){ stream.close();
getLogger().info("[INFO][SESSION] stream: " + stream.getName() + "?" + stream.getQueryStr() + " disconnected from session");
}
}
else {
if (!queryStr.contains(sessionId)){
//disconnect all except initiator
stream.close();
getLogger().info("[INFO][SESSION] stream: " + stream.getName() + "?" + stream.getQueryStr() + " disconnected from session");
}
}
}
}
}
} catch (JSONException e) {
getLogger().error(e.getMessage());
}
}
<br>