Skip to content
Snippets Groups Projects
Commit 23406442 authored by Jesper Fyhr Knudsen's avatar Jesper Fyhr Knudsen
Browse files

Fix bug where SimpleServer will use 100% CPU if the Request is never received

parent bffeecf5
Branches
No related tags found
No related merge requests found
...@@ -74,7 +74,7 @@ public class SimpleServer implements Runnable{ ...@@ -74,7 +74,7 @@ public class SimpleServer implements Runnable{
} catch (SocketException se) { } catch (SocketException se) {
// if the socket is closed it means the server is turned off, so we can ignore the exception // if the socket is closed it means the server is turned off, so we can ignore the exception
if (!socket.isClosed()) se.printStackTrace(); if (!socket.isClosed()) se.printStackTrace();
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -86,8 +86,15 @@ public class SimpleServer implements Runnable{ ...@@ -86,8 +86,15 @@ public class SimpleServer implements Runnable{
return new Response<>(new Response.Error("Endpoint not found: " + request.endpoint)); return new Response<>(new Response.Error("Endpoint not found: " + request.endpoint));
} }
String readRequestFromStream() throws IOException { String readRequestFromStream() throws Exception {
while(socket.getInputStream().available() == 0); long timeout = System.currentTimeMillis() + 5000;
while(socket.getInputStream().available() == 0 && timeout > System.currentTimeMillis()){
Thread.sleep(1);
}
if(socket.getInputStream().available() == 0)
throw new Error("Connection closed before request data was sent");
String requestString = ""; String requestString = "";
......
...@@ -22,20 +22,6 @@ public class HeartbeatTest { ...@@ -22,20 +22,6 @@ public class HeartbeatTest {
assertTrue(chaos.wasHeartbeatSet); assertTrue(chaos.wasHeartbeatSet);
} }
@Test
public void sdfsdf() throws IOException {
Chaos chaos = new Chaos("https://dev-api.cosound.dk/v6");
AuthenticatedChaosClient authenticate = chaos.authenticate("90f4183870e5d60bbb1b595c10f0c48a4edb17a1befeaee3e4146a9d492f0c84");
ClusterState state = new ClusterState();
state.queueSize = 1;
state.agents = new ArrayList<>();
ClusterState.AgentState agentState = new ClusterState.AgentState();
agentState.state = "Disconnected";
state.agents.add(agentState);
authenticate.set(state);
}
private class ChaosMock implements HeartbeatGateway { private class ChaosMock implements HeartbeatGateway {
public boolean wasHeartbeatSet = false; public boolean wasHeartbeatSet = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment