update check: set read timeout on socket, move off of request thread
Update check was hung on read(), which holds a lock causing all other requests for update status to wait
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.http.service.updatecheck;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -36,8 +35,6 @@ import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.worlds.World;
|
||||
import net.runelite.http.api.worlds.WorldResult;
|
||||
@@ -45,6 +42,7 @@ import net.runelite.http.service.worlds.WorldsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -63,7 +61,7 @@ public class UpdateCheckService
|
||||
private static final int RESPONSE_OUTDATED = 6;
|
||||
|
||||
private final WorldsService worldsService;
|
||||
private final Supplier<Boolean> updateAvailable = Suppliers.memoizeWithExpiration(this::checkUpdate, 1, TimeUnit.MINUTES);
|
||||
private boolean updateAvailable;
|
||||
|
||||
@Autowired
|
||||
public UpdateCheckService(WorldsService worldsService)
|
||||
@@ -74,7 +72,13 @@ public class UpdateCheckService
|
||||
@RequestMapping
|
||||
public Boolean check()
|
||||
{
|
||||
return updateAvailable.get();
|
||||
return updateAvailable;
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 60_000)
|
||||
public void scheduledCheck()
|
||||
{
|
||||
updateAvailable = checkUpdate();
|
||||
}
|
||||
|
||||
private boolean checkUpdate()
|
||||
@@ -99,6 +103,7 @@ public class UpdateCheckService
|
||||
|
||||
try (Socket socket = new Socket())
|
||||
{
|
||||
socket.setSoTimeout((int) TIMEOUT.toMillis());
|
||||
socket.connect(new InetSocketAddress(address, PORT), (int) TIMEOUT.toMillis());
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(5);
|
||||
|
||||
Reference in New Issue
Block a user