Page MenuHomeFeedback Tracker

Rest API changing Timeouts not working
Assigned, UrgentPublic

Description

When using the SetOption Function of the Rest API class to change the connect and read timeout, it is not changed and always appies the default 10 seconds timeout
I've setup a local webserver, which accepts connections, but does not send a message back to simulate a timeout, which works fine after 10 seconds, but it cannot be changed (look at the code below)

Details

Severity
Tweak
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

DayZ Script:

modded class MissionServer {
	
	void MissionServer() {
		GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(TestApiTimeouts);
	}
	
	void TestApiTimeouts() {
		int timeout = 3;
		int start = TickCount(0);
		RestApi api = GetRestApi();
		if (!api)
			api = CreateRestApi();
		api.SetOption(ERestOption.ERESTOPTION_READOPERATION, timeout); // Setting the timeout before creating the RestContext or after does not seem to make a difference
		api.SetOption(ERestOption.ERESTOPTION_CONNECTION, timeout);
		RestContext ctx = api.GetRestContext("127.0.0.1:11111");
		api.SetOption(ERestOption.ERESTOPTION_READOPERATION, timeout);
		api.SetOption(ERestOption.ERESTOPTION_CONNECTION, timeout);
		string resp = ctx.POST_now("/", "Data");
		Print("Data: " + resp + " Time: " + (TickCount(start) / 10000) + "ms");
		ctx.POST(new MyTestCallback(), "/", "Data");
	}
	
}

class MyTestCallback : RestCallback {

	int start;
	
	void MyTestCallback() {
		start = TickCount(0);
	}
	
	override void OnError( int errorCode )
	{
		Print("Callback error: " + errorCode + " Time: " + (TickCount(start) / 10000) + "ms");
	}

	override void OnTimeout()
	{
		Print("Timeout. Time: " + (TickCount(start) / 10000) + "ms");
	}

	override void OnSuccess( string data, int dataSize )
	{
		Print("Success. Time: " + (TickCount(start) / 10000) + "ms");
	}
	
}

Scriptlog output:

SCRIPT       : Data: Data Time: 10003ms
SCRIPT       : Callback error: 8 Time: 10085ms

Java Webserver:

public class NoResponseWebserver {

    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(11111);
        System.out.println("Started Server on Port " + socket.getLocalPort());
        while (true) {
            Socket s = socket.accept();
            System.out.println("Accepted Connection from " + s.getInetAddress() + ":" + s.getPort());
            new Thread(() -> {
                try {
                    Thread.sleep(60000);
                    s.close();
                } catch (IOException | InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}

Java Webserver output:

Started Server on Port 11111
Accepted Connection from /127.0.0.1:1188
Accepted Connection from /127.0.0.1:1189

Event Timeline

LBmaster created this task.Apr 3 2023, 8:47 PM
Geez changed the task status from New to Assigned.Apr 4 2023, 10:21 AM